chuweiqiang před 1 rokem
rodič
revize
a44d27efeb

+ 104 - 3
app/admin/controller/ShopProduction.php

@@ -5,6 +5,7 @@ namespace app\admin\controller;
 use app\data\model\DataMerchants;
 use app\data\model\ShopProduction as Model;
 use app\data\model\DataUser;
+use app\data\model\ShopProductionOffer;
 use Carbon\Carbon;
 use think\admin\Controller;
 use app\data\model\SystemUser;
@@ -34,7 +35,7 @@ class ShopProduction extends Controller
         }
         $this->title='生产订单管理';
         $this->assign('status',\app\data\model\ShopPurchase::getStatus());
-        Model::mQuery()
+        $result = Model::mQuery()
             ->equal('status')
             ->dateBetween('create_time')
             ->with(['merchant'])
@@ -42,8 +43,10 @@ class ShopProduction extends Controller
                 $query->hasWhere('merchant',function (Query $query)use ($request){
                     $query->whereLike('name',"%{$request['name']}%");
                 });
-            })->where($admin_id)
-            ->layTable();
+            })->where($admin_id);
+        $this->amount = $result->db()->sum('amount');
+//            ->layTable();
+        $result->page();
     }
     /**
      * 详情
@@ -103,4 +106,102 @@ class ShopProduction extends Controller
             $this->success('保存成功');
         }
     }
+
+    /**
+     * 编辑
+     * @auth true
+     * @menu true
+     */
+    public function edit(Request $request,Model $purchase,\think\Validate $validate){
+        if ($this->request->isGet()) {
+            DataUser::$copyRealName=true;
+            $row = $purchase
+                ->with(['merchant','items','offers','favourite','ppoffer'])
+                ->where('id',$request['id'])->findOrFail();
+            if (!$row['merchant']){
+                $array = ['company'=>'平台发布'];
+                $row['merchant'] = $array;
+            }
+            $this->assign('row',$row);
+            $this->fetch('edit');
+
+        }elseif ($this->request->isPost()){
+            $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
+            if(!$merchant){
+                $this->error('您不是商家无法操作');
+            }
+            $data=$request->post();
+            $item=$data['item']??[];
+            foreach ($item as $i){
+                $make=$validate->check($i,[
+                    'name'=>['require',],
+                    'spec'=>['require',],
+                    'number'=>['require','integer'],
+//                    'standard'=>['require',],
+//                    'price'=>['require','float'],
+//                    'enclosure'=>['require',],
+                ]);
+                if(!$make){
+                    $this->error('请填写正确的商品信息');
+                }
+            }
+//            print_r($data);
+//            exit();
+
+
+
+            app()->db->startTrans();
+            unset($data['item']);
+            $data['admin_id']=AdminService::getUserId();
+            $data['longitude']=$merchant['longitude']??null;
+            $data['latitude']=$merchant['latitude']??null;
+//            $data['amount']=min(array_column($item,'price'));
+            $data['type'] =1;
+//            print_r($data);
+//            exit();
+            //$order= \app\data\model\ShopProduction::create($data);
+            $order=Model::update($data);
+//            $order->items()->saveAll($item);
+            app()->db->commit();
+
+            $item_ids=[];
+            foreach ($item as &$v){
+                $item_data = [
+                    'purchase_id'=>$data['id'],
+                    'name'=>$v['name'],
+                    'spec'=>$v['spec'],
+                    'number'=>$v['number'],
+//                    'standard'=>$v['standard'],
+//                    'price'=>$v['price'],
+                ];
+                if(!empty($v['id'])){
+                    $itemModel=$order->items()->where('id',$v['id'])->find();
+                    if(!$itemModel){
+                        $this->error('商品不存在');
+                    }
+                    $itemModel->save($item_data);
+                }else{
+                    $itemModel=$order->items()->save($item_data);
+                }
+                $item_ids[]=$itemModel['id'];
+            }
+            $order = $order->items()->whereNotIn('id',$item_ids)->select()->each(function ($d){$d->delete();});
+                ShopProductionOffer::where('order_id',$data['id'])
+                ->whereNotIn('item_id',$item_ids)
+                ->select()->each(function ($m){$m->delete();});
+            $this->success('保存成功');
+        }
+    }
+
+    /**
+     * 取消订单
+     * @auth true
+     * @menu true
+     */
+    public function cancellation(Request $request,Model $purchase){
+        $purchase_=$purchase->where('id',$request['id'])->findOrFail();
+        $purchase_['status']=0;
+        $purchase_->save();
+        $this->success('取消成功');
+    }
 }

+ 200 - 0
app/admin/view/shop_production/edit.html

@@ -0,0 +1,200 @@
+{extend name="../../admin/view/main"}
+{block name='content'}
+<style>
+    .layui-card-body{
+        background: white;
+    }
+    #newForm{
+        width: 80%;
+    }
+    .image{
+        width: 100px;
+        height: 100px;
+    }
+    .video{
+        width: 200px;
+        height: 200px;
+    }
+    .child-form{
+        width: 500px;
+        background: #f4f4f4;
+        padding: 10px;
+        display: inline-block;
+    }
+</style>
+<div id="newForm">
+    <el-form :model="form" label-width="140px" ref="form" size="medium">
+        <el-form-item label="联系人" prop="real_name" :rules="{message:'此项必须',required:true}">
+            <el-input v-model="form.real_name"></el-input>
+        </el-form-item>
+        <el-form-item label="联系电话" prop="mobile" :rules="{message:'此项必须',required:true}">
+            <el-input v-model="form.mobile"></el-input>
+        </el-form-item>
+        <el-form-item label="生产技术标准" prop="standard_tech" :rules="{message:'此项必须',required:true}">
+            <el-input v-model="form.standard_tech"></el-input>
+        </el-form-item>
+        <el-form-item label="生产验收标准" prop="standard_check" :rules="{message:'此项必须',required:true}">
+            <el-input v-model="form.standard_check"></el-input>
+        </el-form-item>
+
+        <el-form-item label="商品信息:" prop="item" :rules="[{message:'此项必须',required:true},{type:'array',min:1,message:'需要商品信息'}]">
+            <div><el-button @click="addItem">添加</el-button></div>
+            <div v-for="(item,idx) in form.item" class="child-form">
+                <i class="el-icon-delete" @click="deleteItem(idx)"></i>
+                <el-form-item label="商品名称">
+                    <el-input v-model="item.name"></el-input>
+                </el-form-item>
+                <el-form-item label="规格">
+                    <el-input v-model="item.spec"></el-input>
+                </el-form-item>
+                <el-form-item label="数量">
+                    <el-input v-model="item.number"></el-input>
+                </el-form-item>
+                <!--                <el-form-item label="质量标准">-->
+                <!--                    <el-input v-model="item.standard"></el-input>-->
+                <!--                </el-form-item>-->
+                <!--                <el-form-item label="采购价">-->
+                <!--                    <el-input v-model="item.price"></el-input>-->
+                <!--                </el-form-item>-->
+                <el-form-item label="文件" prop="enclosure">
+                    <el-button @click="addFiles(null,item.enclosure)">增加</el-button>
+                    <div>
+                        <span v-for="(val,idx) in item.enclosure" :key="idx">
+                            <el-tag type="text" @close="item.enclosure.splice(idx,1)" closable>{{val.filename}}</el-tag>
+                        </span>
+                    </div>
+                </el-form-item>
+            </div>
+        </el-form-item>
+
+        <el-form-item label="图片视频" prop="files">
+            <el-button @click="addFile('image')">增加图片/视频</el-button>
+            <div>
+                <div v-for="(item,idx) in form.images" :key="idx" style="display: inline-block;">
+                    <el-image v-if="item.type==='image'" :src="item.src" class="video"></el-image>
+                    <video controls v-else :src="item.src" class="video"></video>
+                    <a @click="form.images.splice(idx,1)">删除</a>
+                </div>
+            </div>
+        </el-form-item>
+        <el-form-item label="交货地址" :rules="{message:'此项必须',required:true}" prop="post_address">
+            <el-input v-model="form.post_address"></el-input>
+        </el-form-item>
+        <el-form-item label="交货时间" :rules="{message:'此项必须',required:true}" prop="post_time">
+            <el-date-picker type="datetime" v-model="form.post_time" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
+        </el-form-item>
+        <el-form-item>
+            <el-button type="primary" @click="save" :loading="saving">保存</el-button>
+            <el-button @click="history.back()">取消</el-button>
+        </el-form-item>
+    </el-form>
+    <div style="display: none;">
+        <button data-type="zip" data-file id="fileUpload"></button>
+    </div>
+</div>
+<script>
+    let editorContent;
+    let vo={:json_encode($row?:null,256)};
+    let audit=vo.audit
+    if(audit===1){
+        vo.audit=2
+    }
+    require(['ckeditor'], function () {
+
+    });
+    vo.item=vo.items
+    new Vue({
+        el:'#newForm',
+        data:()=>({
+            form:vo||{
+                real_name:null,
+                mobile:null,
+                standard_tech:null,
+                standard_check:null,
+                item:[],
+                images:[],
+            },
+            saving:false,
+        }),
+        methods:{
+            addItem(){
+                let that = this;
+                that.form.item.push({
+                    name:null,
+                    spec:null,
+                    number:null,
+                    // standard:null,
+                    // price:null,
+                    enclosure:[]
+                })
+            },
+            deleteItem (key) {
+                this.form.item.splice(key, 1)
+            },
+            addFile(){
+                $('#fileUpload').unbind('upload.done')
+                $('#fileUpload').on('upload.done',  (e,obj) => {
+                    let type=obj.file.type.split('/')[0]
+                    if(['image','video'].indexOf(type)===-1){
+                        this.$message.error('请上传正确的格式')
+                        return
+                    }
+                    this.form.images.push({
+                        type:type,
+                        src:obj.data.url
+                    })
+                });
+                $('#fileUpload').trigger('click')
+            },
+            addFiles(ext,form){
+                $('#fileUpload').unbind('upload.done')
+                $('#fileUpload').on('upload.done',  (e,obj) => {
+                    if(ext && obj.file.type.indexOf(ext)===-1){
+                        this.$message.error('请上传正确的格式')
+                        return
+                    }
+                    // console.log(obj.file.name);
+                    // alert(obj.file.name);
+                    // console.log({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
+                    form.push({fileurl:obj.data.url,filename:obj.data.url.split('/')[obj.data.url.split('/').length-1]})
+                });
+                $('#fileUpload').trigger('click')
+            },
+            save(){
+                let _this=this,
+                    form=this.form
+                // form.item=form.item.map(item1=>{
+                //     item1.enclosure=item1.enclosure.map(item=>{
+                //         return {fileurl:item,filename:1235}
+                //     })
+                //     return item1
+                // })
+                console.log(form)
+                this.$refs.form.validate(v=>{
+                    if(!v){
+                        return
+                    }
+                    $.ajax('{:sysuri()}',{
+                        data:form,
+                        type:'post',
+                        beforeSend(){
+                            _this.saving=true
+                        },
+                        success({code,info}){
+                            if(code){
+                                _this.$message.success('保存成功')
+                                window.history.back()
+                            }else{
+                                _this.$message.error(info)
+                            }
+                        },
+                        complete(){
+                            _this.saving=false
+                        }
+                    })
+                })
+            }
+        }
+    })
+</script>
+{/block}

+ 76 - 2
app/admin/view/shop_production/index.html

@@ -44,7 +44,81 @@
                 <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> 搜 索</button>
             </div>
         </form>
-        <table id="NewsTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>
+        <div class="layui-tab-content">
+
+            <table class="layui-table margin-top-10" lay-skin="line">
+                {notempty name='list'}
+                <thead>
+                <tr>
+                    <th>ID</th>
+                    <th>订单号</th>
+                    <th>商家名称</th>
+                    <th>联系人</th>
+                    <th>联系方式</th>
+                    <th>交货地址</th>
+                    <th>交货时间</th>
+<!--                    <th>已报价价格</th>-->
+                    <th>发布时间</th>
+                    <th>操作面板</th>
+                </tr>
+                </thead>
+                {/notempty}
+                <tbody>
+                {foreach $list as $key=>$vo}
+                <tr>
+                    <!--                <td class='list-table-check-td think-checkbox'>-->
+                    <!--                    <label><input class="list-check-box" type='checkbox' value='{$vo.id}'></label>-->
+                    <!--                </td>-->
+                    <td class="nowrap">
+                        {$vo.id}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.order_no}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.merchant.name}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.real_name}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.mobile}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.post_address}
+                    </td>
+                    <td class="nowrap">
+                        {$vo.post_time}
+                    </td>
+<!--                    <td class="nowrap">-->
+<!--                        {if $vo.amount == 0.00}-->
+<!--                        '未匹配'-->
+<!--                        {else}-->
+<!--                        {$vo.amount}-->
+<!--                        {/if}-->
+<!--                    </td>-->
+                    <td class="nowrap">
+                        {$vo.create_time}
+                    </td>
+
+                    <td class="nowrap">
+                        <div>
+                            <a class="layui-btn layui-btn-primary layui-btn-sm" data-modal="{:url('detail')}?id={$vo.id}" data-area='["1200px","90%"]'>查看详情</a>
+                            {if $vo.status == 1}
+                            <a class="layui-btn layui-btn-primary layui-btn-sm" data-open="{:url('edit')}?id={$vo.id}" data-area='["1200px","90%"]'>编辑</a>
+
+                            <a class="layui-btn layui-btn-primary layui-btn-sm" data-confirm="确定要取消订单吗?" data-action="{:url('cancellation')}?id={$vo.id}" data-area='["1200px","90%"]'>取消订单</a>
+                            {/if}
+                        </div>
+                    </td>
+                </tr>
+                {/foreach}
+                </tbody>
+            </table>
+            {empty name='list'}<span class="notdata">没有记录哦</span>{else}{$pagehtml|raw|default=''}{/empty}
+
+        </div>
+<!--        <table id="NewsTable" data-url="{:sysuri()}" data-target-search="form.form-search"></table>-->
     </div>
 </div>
 {/block}
@@ -112,4 +186,4 @@
     <a class="layui-btn layui-btn-primary layui-btn-sm" data-modal="{:url('detail')}?id={{d.id}}" data-area='["1200px","90%"]'>查看详情</a>
     <!--{/if}-->
 </script>
-{/block}
+{/block}

+ 2 - 2
app/data/service/PaymentService.php

@@ -376,7 +376,7 @@ abstract class PaymentService
             $item->save();
 
         }
-        ShopOrder::mk()->where(['payment_trade'=>$orderNo])->save(['status'=>4,'payment_datetime'=>date('Y-m-d H:i:s'),'payment_status'=>1]);
+        ShopOrder::mk()->where(['payment_trade'=>$orderNo])->where('status',2)->save(['status'=>4,'payment_datetime'=>date('Y-m-d H:i:s'),'payment_status'=>1]);
 
         //商家消息提醒
         $order_info = ShopOrder::mk()->where(['payment_trade'=>$orderNo])->field('order_no,admin_id')->find();
@@ -440,4 +440,4 @@ abstract class PaymentService
         }
         return true;
     }
-}
+}