title='外协订单管理'; $this->assign('status',\app\data\model\ShopPurchase::getStatus()); $result = Model::mQuery() ->with(['merchant']) ->when($request['name'],function (Query $query)use ($request){ $query->hasWhere('merchant',function (Query $query)use ($request){ $query->whereLike('name',"%{$request['name']}%"); }); })->where($admin_id) ->equal('status') ->dateBetween('create_time'); // ->layTable(); $this->amount = $result->db()->sum('amount'); $result->page(); } /** * 详情 * @auth true * @menu true */ public function detail(Request $request,Model $purchase){ DataUser::$copyRealName=true; $this->assign('row',$purchase ->with(['merchant','items','offers','offers.user']) ->where('id',$request['id'])->findOrFail()); $this->fetch('form'); } /** * 发布 * @auth true * @menu true */ public function add(Request $request,\think\Validate $validate){ $this->title='发布订单'; $this->assign('vo',null); if($request->isGet()) { $this->fetch(); }else{ $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'], // 'enclosure'=>['require',], // 'price'=>['require','float'], ]); if(!$make){ $this->error('请填写正确的商品信息'); } } 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; $order= \app\data\model\ShopCoordination::create($data); $order->items()->saveAll($item); app()->db->commit(); $this->success('保存成功'); } } /** * 发布 * @auth true * @menu true */ public function edit(Request $request,Model $purchase,\think\Validate $validate){ $this->title='发布订单'; $this->assign('vo',null); if($request->isGet()) { $row = $purchase ->with(['merchant','items','offers','favourite','ppoffer']) ->where('id',$request['id'])->findOrFail(); if (!$row['merchant']){ $array = ['company'=>'平台发布']; $row['merchant'] = $array; } // var_dump($row['form']);die; // $row['fm'] = explode(',',$row['form']); //$row['images'] = $row['file']; if($row['file'] == '' || $row['file'] == null){ $row['file'] = []; } $this->assign('row',$row); $this->fetch('edit'); }else{ $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'], // 'enclosure'=>['require',], // 'price'=>['require','float'], ]); if(!$make){ $this->error('请填写正确的商品信息'); } } 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; if(!$data['offer_id']){ unset($data['offer_id']); } if(isset($data['file'])){ // $data['file'] = $data['images']; }else{ $data['file'] = null; } // $order= \app\data\model\ShopCoordination::create($data); $order=Model::update($data); foreach ($item as &$v){ if(isset($v['enclosure'])){ $v['enclosure'] = $v['enclosure']; }else{ $v['enclosure'] = []; } } $order->items()->saveAll($item); app()->db->commit(); $this->success('保存成功'); } } /** * 取消订单 * @auth true * @menu true */ public function cancellation(Request $request, \app\data\model\ShopCoordination $purchase){ $purchase_=$purchase->where('id',$request['id'])->findOrFail(); $purchase_['status']=0; $purchase_->save(); $this->success('取消成功'); } }