|
@@ -5,6 +5,7 @@ namespace app\admin\controller;
|
|
use app\data\model\DataMerchants;
|
|
use app\data\model\DataMerchants;
|
|
use app\data\model\ShopProduction as Model;
|
|
use app\data\model\ShopProduction as Model;
|
|
use app\data\model\DataUser;
|
|
use app\data\model\DataUser;
|
|
|
|
+use app\data\model\ShopProductionOffer;
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
use think\admin\Controller;
|
|
use think\admin\Controller;
|
|
use app\data\model\SystemUser;
|
|
use app\data\model\SystemUser;
|
|
@@ -34,7 +35,7 @@ class ShopProduction extends Controller
|
|
}
|
|
}
|
|
$this->title='生产订单管理';
|
|
$this->title='生产订单管理';
|
|
$this->assign('status',\app\data\model\ShopPurchase::getStatus());
|
|
$this->assign('status',\app\data\model\ShopPurchase::getStatus());
|
|
- Model::mQuery()
|
|
|
|
|
|
+ $result = Model::mQuery()
|
|
->equal('status')
|
|
->equal('status')
|
|
->dateBetween('create_time')
|
|
->dateBetween('create_time')
|
|
->with(['merchant'])
|
|
->with(['merchant'])
|
|
@@ -42,8 +43,10 @@ class ShopProduction extends Controller
|
|
$query->hasWhere('merchant',function (Query $query)use ($request){
|
|
$query->hasWhere('merchant',function (Query $query)use ($request){
|
|
$query->whereLike('name',"%{$request['name']}%");
|
|
$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('保存成功');
|
|
$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('取消成功');
|
|
|
|
+ }
|
|
}
|
|
}
|