123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717 |
- <?php
- namespace app\data\controller\api\business;
- use app\data\model\DataUser;
- use app\data\model\DataUserLeaveMessage;
- use app\data\model\ShopCoordination;
- use app\data\model\ShopCoordinationItem;
- use app\data\model\ShopOcean;
- use app\data\model\ShopOceanItem;
- use app\data\model\ShopProduction;
- use app\data\model\ShopProductionItem;
- use app\data\model\ShopPurchase;
- use app\data\model\ShopPurchaseItem;
- use app\data\model\ShopPurchaseOffer;
- use app\data\model\ShopPurchaseOfferAmount;
- use app\data\model\SystemUser;
- use think\admin\Controller;
- use think\Exception;
- use think\exception\ErrorException;
- use think\facade\Db;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Returned;
- use think\facade\Validate;
- use think\Request;
- /**
- * 商家端发布订单
- * Class Goods
- * @package app\data\controller\api
- */
- class Purchase extends Controller
- {
- /**
- * @Title ("采购订单发布和编辑")
- * @Method ("post")
- * @Param ("id",desc="如果是编辑则传ID")
- * @Param ("real_name",desc="联系人")
- * @Param ("mobile",desc="联系方式")
- * @Param ("post_time",desc="交货时间")
- * @Param ("post_address",desc="交货地址")
- * @Param ("images",desc="图片数组,[{type:'image或video',src:'http://xxxxx'}]")
- * @Param ("item",desc="['id:修改则传ID','name 商品名称','spec 规格','number 数量','standard 验收标准','price 价格']")
- * @return void
- */
- public function purchase_order(\think\Validate $validate,Request $request){
- $request->offsetSet('images',json_decode($request['images'],true)?:[]);
- $request->offsetSet('item',json_decode($request['item'],true)?:[]);
- $admin_id = $this->uuid();
- $data=$this->_vali([
- 'real_name.require'=>'联系人不能为空',
- 'mobile.require'=>'联系方式不能为空',
- 'post_time.require'=>'交货时间不能为空',
- 'post_address.require'=>'交货单地址不能为空',
- // 'images.require'=>'图片不能为空',
- // 'images.array'=>'图片格式有误',
- // 'images.min:1'=>'图片必须',
- 'item.require'=>'商品参数不能为空',
- ]);
- $images = $this->request->post('images');
- if(isset($images) && $images!=null){
- $data['images'] = json_decode($request['images'],true);
- foreach ($data['images'] as $image){
- $validate->failException()->check($image,[
- 'type|图片类型'=>['require','in:image,video'],
- 'src|图片链接'=>['require','url'],
- ]);
- }
- }
- $data['item'] = json_decode($request['item'],true);
- foreach ($data['item'] as $item){
- $validate->failException()->check($item,[
- 'name|名称'=>['require'],
- 'spec|规格'=>['require'],
- 'number|数量'=>['require','integer'],
- // 'standard|验收标准'=>['require'],
- // 'price|价格'=>['require','float'],
- ]);
- }
- $purchase_data = [
- 'admin_id'=>$admin_id->id,
- 'real_name'=>$data['real_name'],
- 'mobile'=>$data['mobile'],
- // 'images'=>$data['images'],
- 'post_time'=>$data['post_time'],
- 'post_address'=>$data['post_address'],
- 'create_time'=>date('Y-m-d H:i:s'),
- 'longitude'=>$admin_id->merchant->longitude,
- 'latitude'=>$admin_id->merchant->latitude,
- 'amount'=>min(array_column($data['item'],'price')),
- ];
- isset($data['images'])?$purchase_data['images']=$data['images']:'';
- Db::startTrans();
- try {
- if($request['id']){
- $order_id=ShopPurchase::where('admin_id',$admin_id['id'])->where('id',$request['id'])->findOrFail();
- $order_id->save($purchase_data);
- }else {
- $order_id = ShopPurchase::create($purchase_data);
- }
- $item_ids=[];
- foreach ($data['item'] as &$v){
- $item_data = [
- 'purchase_id'=>$order_id['id'],
- 'name'=>$v['name'],
- 'spec'=>$v['spec'],
- 'number'=>$v['number'],
- 'standard'=>$v['standard'],
- 'price'=>$v['price'],
- ];
- if(!empty($v['id'])){
- $itemModel=$order_id->items()->where('id',$v['id'])->find();
- if(!$itemModel){
- $this->error('商品不存在');
- }
- $itemModel->save($item_data);
- }else{
- $itemModel=$order_id->items()->save($item_data);
- }
- $item_ids[]=$itemModel['id'];
- }
- $order_id->items()->whereNotIn('id',$item_ids)->select()->each(function ($d){$d->delete();});
- ShopPurchaseOffer::where('order_id',$order_id['id'])
- ->whereNotIn('item_id',$item_ids)
- ->select()->each(function ($m){$m->delete();});
- // 提交事务
- Db::commit();
- $this->success('采购订单发布成功');
- } catch (ErrorException $e) {
- // 回滚事务
- Db::rollback();
- $this->error('发布失败');
- }
- }
- /**
- * @Title ("生产订单发布或编辑")
- * @Method ("post")
- * @Param ("id",desc="如果是编辑则传ID")
- * @Param ("real_name",desc="联系人")
- * @Param ("mobile",desc="联系方式")
- * @Param ("standard_tech",desc="生产技术标准")
- * @Param ("standard_check",desc="生产验收标准")
- * @Param ("post_time",desc="交货时间")
- * @Param ("post_address",desc="交货地址")
- * @Param ("file",desc="图片/视频,[{type:'image或video',src:'http://xxxxx'}]")
- * @Param ("item",desc="二维数组,[{'id:修改则传ID',name:'产品名称',spec:'规格',number:'数量',enclosure:[{filename:'文件名',fileurl:'文件链接'}]}]")
- * @return void
- */
- public function production_order(\think\Validate $validate,Request $request){
- $admin_id = $this->uuid();
- $request->offsetSet('file',json_decode($request['file'],true)?:[]);
- $request->offsetSet('item',json_decode($request['item'],true)?:[]);
- $data=$this->_vali([
- 'real_name.require'=>'联系人不能为空',
- 'mobile.require'=>'联系方式不能为空',
- // 'standard_tech.require'=>'生产技术标准必须',
- // 'standard_check.require'=>'生产验收标准必须',
- 'post_time.require'=>'交货时间不能为空',
- 'post_address.require'=>'交货单地址不能为空',
- 'item.require'=>'商品参数不能为空',
- //'file.array'=>'图片视频有误',
- ]);
- // exit;
- $data['item'] = json_decode($request['item'],true);
- if(input('file')){
- $data['file'] = json_decode($request['file'],true);
- foreach ($data['file']??[] as $image){
- $validate->failException()->check($image,[
- 'type|图片类型'=>['require','in:image,video'],
- 'src|图片链接'=>['require','url'],
- ]);
- }
- }
- foreach ($data['item'] as $item){
- $validate->failException()->check($item,[
- 'name|名称'=>['require'],
- 'spec|规格'=>['require'],
- 'number|数量'=>['require','integer'],
- // 'enclosure|附件'=>['array',],
- ]);
- // if(!empty($item['enclosure'])){
- // foreach ($item['enclosure'] as $enclosure){
- // $validate->failException()->check($enclosure,[
- // 'filename|文件名'=>['require'],
- // 'fileurl|文件地址'=>['require','url',],
- // ]);
- // }
- // }
- }
- $purchase_data = [
- 'admin_id'=>$admin_id->id,
- 'real_name'=>$data['real_name'],
- 'mobile'=>$data['mobile'],
- // 'standard_tech'=>$data['standard_tech'],
- // 'standard_check'=>$data['standard_check'],
- 'post_time'=>$data['post_time'],
- 'post_address'=>$data['post_address'],
- 'longitude'=>$admin_id->merchant->longitude,
- 'latitude'=>$admin_id->merchant->latitude,
- 'create_time'=>date('Y-m-d H:i:s'),
- 'file'=>$data['file']??[],
- ];
- input('standard_tech')?$purchase_data['standard_tech']=input('standard_tech'):'';
- input('standard_check')?$purchase_data['standard_check']=input('standard_check'):'';
- $input = input();
- if(!isset($input['standard_tech'])){
- $purchase_data['standard_tech'] = '';
- }
- if(!isset($input['standard_check'])){
- $purchase_data['standard_tech'] = '';
- }
- Db::startTrans();
- try {
- if($request['id']) {
- $order=ShopProduction::where('admin_id',$admin_id['id'])->where('id',$request['id'])->findOrFail();
- $order->save($purchase_data);
- $item_ids=[];
- foreach ($data['item'] as $item){
- if(!empty($item['id'])){
- $itemModel=$order->items()->where('id',$item['id'])->findOrFail();
- $itemModel->save($item);
- }else{
- $itemModel=$order->items()->save($item);
- }
- $item_ids[]=$itemModel['id'];
- }
- $order->items()->whereNotIn('id',$item_ids)->select()->each(function ($d){$d->delete();});
- }else{
- $order = ShopProduction::create($purchase_data);
- $order->items()->saveAll($data['item']);
- }
- // 提交事务
- Db::commit();
- $this->success('订单已发布');
- } catch (ErrorException $e) {
- // 回滚事务
- Db::rollback();
- $this->success('发布失败');
- }
- }
- /**
- * @Title ("海运订单发布或编辑")
- * @Method ("post")
- * @Param ("id",desc="如果是编辑则传ID")
- * @Param ("real_name",desc="联系人")
- * @Param ("mobile",desc="联系方式")
- * @Param ("form",desc="包装形式")
- * @Param ("wharf_to",desc="装货码头")
- * @Param ("wharf_for",desc="交货码头")
- * @Param ("file",desc="图片/视频,[{type:'image或video',src:'http://xxxxx'}]")
- * @Param ("item",desc="['id:修改则传ID','name 商品名称','weight 重量']")
- * @return void
- */
- public function ocean_order(\think\Validate $validate,Request $request){
- $request->offsetSet('file',json_decode($request['file'],true)?:[]);
- $request->offsetSet('item',json_decode($request['item'],true)?:[]);
- $admin_id = $this->uuid();
- $data=$this->_vali([
- 'real_name.require'=>'联系人不能为空',
- 'mobile.require'=>'联系方式不能为空',
- 'form.require'=>'包装形式必须',
- 'wharf_to.require'=>'装货码头必须',
- 'wharf_for.require'=>'交货码头必须',
- // 'file.array'=>'图片必须是数组',
- 'item.require'=>'商品必须',
- 'item.array'=>'商品必须是数组',
- ]);
- $data['item'] = json_decode($request['item'],true);
- if(input('file')){
- $data['file'] = json_decode($request['file'],true);
- foreach ($data['file']??[] as $image){
- $validate->failException()->check($image,[
- 'type|图片类型'=>['require','in:image,video'],
- 'src|图片链接'=>['require','url'],
- ]);
- }
- }
- foreach ($data['item'] as $item){
- $validate->failException()->check($item,[
- 'name|名称'=>['require'],
- 'weight|数量吨位'=>['require'],
- ]);
- }
- $purchase_data = [
- 'admin_id'=>$admin_id->id,
- 'real_name'=>$data['real_name'],
- 'mobile'=>$data['mobile'],
- 'form'=>$data['form'],
- 'wharf_to'=>$data['wharf_to'],
- 'wharf_for'=>$data['wharf_for'],
- 'file'=>$data['file']??[],
- 'longitude'=>$admin_id->merchant->longitude,
- 'latitude'=>$admin_id->merchant->latitude,
- ];
- Db::startTrans();
- try {
- if($request['id']){
- $order_id=ShopOcean::where('admin_id',$admin_id['id'])->where('id',$request['id'])->findOrFail();
- $order_id->save($purchase_data);
- $item_ids=[];
- foreach ($data['item'] as $item){
- if(!empty($item['id'])){
- $itemModel=$order_id->items()->where('id',$item['id'])->findOrFail();
- $itemModel->save($item);
- }else{
- $itemModel=$order_id->items()->save($item);
- }
- $item_ids[]=$itemModel['id'];
- }
- $order_id->items()->whereNotIn('id',$item_ids)->select()->each(function ($d){$d->delete();});
- }else {
- $order_id = ShopOcean::mk()->create($purchase_data);
- $order_id->items()->saveAll($data['item']);
- }
- // 提交事务
- Db::commit();
- $this->success('已发布');
- } catch (ErrorException $e) {
- // 回滚事务
- Db::rollback();
- $this->success('发布失败');
- }
- }
- /**
- * @Title ("外协订单发布或编辑")
- * @Method ("post")
- * @Param ("id",desc="如果是编辑则传ID")
- * @Param ("real_name",desc="联系人")
- * @Param ("mobile",desc="联系方式")
- * @Param ("standard_tech",desc="生产技术标准")
- * @Param ("standard_check",desc="生产验收标准")
- * @Param ("post_time",desc="交货时间")
- * @Param ("post_address",desc="交货地址")
- * @Param ("file",desc="图片/视频,[{type:'image或video',src:'http://xxxxx'}]")
- * @Param ("item",desc="二维数组,[{'id:修改则传ID',name:'产品名称',spec:'规格',number:'数量',enclosure:[{filename:'文件名',fileurl:'文件链接'}]}]")
- * @return void
- */
- public function coordination_order(\think\Validate $validate,Request $request){
- $request->offsetSet('file',json_decode($request['file'],true)?:[]);
- $request->offsetSet('item',json_decode($request['item'],true)?:[]);
- $admin_id = $this->uuid();
- $data=$this->_vali([
- 'real_name.require'=>'联系人不能为空',
- 'mobile.require'=>'联系方式不能为空',
- // 'standard_tech.require'=>'生产技术标准',
- // 'standard_check.require'=>'生产验收标准',
- 'post_time.require'=>'交货时间不能为空',
- 'post_address.require'=>'交货单地址不能为空',
- 'item.require'=>'商品参数不能为空',
- // 'file.array'=>'图片必须是数组',
- ]);
- $data['item'] = json_decode($request['item'],true);
- if(input('file')) {
- $data['file'] = json_decode($request['file'],true);
- foreach ($data['file'] ?? [] as $image) {
- $validate->failException()->check($image, [
- 'type|图片类型' => ['require', 'in:image,video'],
- 'src|图片链接' => ['require', 'url'],
- ]);
- }
- }
- foreach ($data['item'] as $item){
- $validate->failException()->check($item,[
- 'name|名称'=>['require'],
- 'spec|规格'=>['require'],
- 'number|数量'=>['require','integer'],
- // 'enclosure|附件'=>['array',],
- ]);
- // if(!empty($item['enclosure'])){
- // foreach ($item['enclosure'] as $enclosure){
- // $validate->failException()->check($enclosure,[
- // 'filename|文件名'=>['require'],
- // 'fileurl|文件地址'=>['require','url',],
- // ]);
- // }
- // }
- }
- $purchase_data = [
- 'admin_id'=>$admin_id->id,
- 'real_name'=>$data['real_name'],
- 'mobile'=>$data['mobile'],
- // 'standard_tech'=>$data['standard_tech'],
- // 'standard_check'=>$data['standard_check'],
- 'post_time'=>$data['post_time'],
- 'post_address'=>$data['post_address'],
- 'longitude'=>$admin_id->merchant->longitude,
- 'latitude'=>$admin_id->merchant->latitude,
- 'file'=>$data['file']??[],
- 'create_time'=>date('Y-m-d H:i:s')
- ];
- input('standard_tech')?$purchase_data['standard_tech']=input('standard_tech'):'';
- input('standard_check')?$purchase_data['standard_check']=input('standard_check'):'';
- Db::startTrans();
- try {
- if($request['id']){
- $order=ShopCoordination::where('id',$request['id'])->where('admin_id',$admin_id['id'])->findOrFail();
- $order->save($purchase_data);
- $item_ids=[];
- foreach ($data['item'] as $item){
- if(!empty($item['id'])){
- $itemModel=$order->items()->where('id',$item['id'])->findOrFail();
- $itemModel->save($item);
- }else{
- $itemModel=$order->items()->save($item);
- }
- $item_ids[]=$itemModel['id'];
- }
- $order->items()->whereNotIn('id',$item_ids)->select()->each(function ($d){$d->delete();});
- }else {
- $order = ShopCoordination::mk()->create($purchase_data);
- $order->items()->saveAll($data['item']);
- }
- // 提交事务
- Db::commit();
- $this->success('已发布');
- } catch (ErrorException $e) {
- // 回滚事务
- Db::rollback();
- $this->success('发布失败');
- }
- }
- public function order_no($key,$uuid){
- $time_str = date('YmdHi');
- $order_no = $key.$time_str . sprintf("%04d", $uuid);
- return $order_no;
- }
- public function uuid(){
- $purchase_model = new Common($this->app);
- $uuid = $purchase_model->uuid();
- return $uuid;
- }
- /**
- * @Title("采购订单列表")
- * @Param ("page",desc="第几页")
- * @Param ("limit",desc="每页几条")
- * @Param ("status",desc="1未报价2已报价3已匹配")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Returned("参考用户端采购订单列表")
- */
- public function list(Request $request){
- $status=$request['status'];
- $tab=$request['tab']?:1;
- $query=ShopPurchase::getQuery($tab);
- $list=$query
- ->where('admin_id',$this->uuid()->id)
- ->when($tab,function ($query) use ($tab,$status){
- if ($tab==1){
- $query ->with(['items','items.offers']);
- $query->when($status,function ($query)use($status){
- if($status == 1){
- $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and not exists(select * from shop_purchase_offer where shop_purchase_offer.item_id=shop_purchase_item.id)');
- }elseif ($status == 2){
- $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and exists(select * from shop_purchase_offer where shop_purchase_offer.item_id=shop_purchase_item.id)');
- }elseif($status == 3){
- $query->whereExists('select * from shop_purchase_item where shop_purchase_item.purchase_id=shop_purchase.id and offer_id is not null');
- }else{
- $this->error('未知参数');
- }
- });
- }else{
- $query ->with(['items','offers']);
- }
- })
- ->when($tab!=1&&$status,['status'=>$status])
- ->order('create_time','desc')
- ->paginate($request['limit']?:15);
- $this->success('',$list);
- }
- /**
- *@Title("详情")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("id",desc="订单ID")
- * @Returned("is_matched",desc="是否已匹配")
- * @Returned("参考用户端采购订单列表")
- */
- public function show(Request $request){
- DataUser::$copyRealName=true;
- $data=$this->_vali([
- 'id.require'=>'ID必须',
- 'tab.require'=>'tab必须',
- ],'get');
- if($data['tab']==1) {
- $model = ShopPurchase::getQuery($data['tab'])
- ->with(['items','items.offers','items.offers.user'])
- ->findOrFail($data['id']);
- foreach ($model['items'] as &$v){
- $arr = [];
- foreach ($v['offers'] as $aa=>&$a){
- if($a['id']!=$v['offer_id'] && $v['offer_id']!=''){
- // unset($v['offers'][$aa]);
- }else{
- $arr[] = $v['offers'][$aa];
- // return $v['offers'][$aa];
- }
- $a['amounts'] = ShopPurchaseOfferAmount::mk()
- ->where('user_id',$a['user_id'])
- ->where('offer_id',$a['id'])
- ->order('id asc')
- ->select();
- }
- $v['offers'] = $arr;
- }
- }else{
- $model = ShopPurchase::getQuery($data['tab'])
- ->with(['items','offers','offers.user'])
- ->findOrFail($data['id']);
- }
- //return json($model);
- $this->success('',$model);
- }
- /**
- *@Title("取消订单")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("id",desc="订单ID")
- */
- public function cancel(Request $request){
- $data=$this->_vali([
- 'id.require'=>'ID必须',
- 'tab.require'=>'tab必须',
- ],'get');
- $admin=$this->uuid();
- $model=ShopPurchase::getQuery($data['tab'])->where('admin_id',$admin['id'])->findOrFail($data['id']);
- $model['status']=0;
- $model->save();
- $this->success('操作成功');
- }
- /**
- *@Title("提醒完成")
- * @Param ("user_id",desc="用户ID")
- * @Param ("order_no",desc="订单号")
- */
- public function reminder(Request $request){
- $admin_id = $this->uuid();
- $data=$this->_vali([
- 'user_id.require'=>'user_id必须',
- 'order_no.require'=>'订单号必须'
- ],'get');
- $alias = DataUser::mk()->where('id',$data['user_id'])->value('jgalias');
- // $content = '您报价的订单已匹配完成,请及时查看';
- $content = '商家“'.$admin_id->nickname.'”提醒您要及时完成生产订单哦,订单号:'.$data['order_no'];
- $alias ? jgpush($content,$alias) : '';
- setusermessage($data['user_id'],'匹配通知',$content);
- $this->success('操作成功');
- }
- /**
- * @Title("匹配订单")
- * @Method("POST")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("id",desc="订单ID")
- * @Param ("offer_id",desc="接单ID")
- */
- public function match(Request $request){
- $data=$this->_vali([
- 'id.require'=>'ID必须',
- 'tab.require'=>'tab必须',
- 'offer_id.require'=>'offer必须',
- ]);
- $admin=$this->uuid();
- $tab = $data['tab'];
- $id = $data['id'];
- Db::startTrans();
- // $admin['id'] = '10010';
- $model=ShopPurchase::getItem($data['tab'],$admin['id'])->lock(true)
- ->where(function ($query) use ($tab,$id){
- // if ($tab==1){
- // $query->where('purchase_id',$id);
- // }else{
- $query->where('id',$id);
- // }
- })
- ->findOrEmpty();
- $model_id = $model['id'];
- //dump($model->toArray());die;
- if($model['is_matched']){
- Db::rollback();
- $this->error('该订单已匹配');
- }
- // $hasMatch=ShopPurchase::getItem($data['tab'])->where('offer_id',$data['offer_id'])->value('id');
- $hasMatch=ShopPurchase::getItem($data['tab'])->where('id',$data['id'])->value('offer_id');
- if($hasMatch){
- Db::rollback();
- $this->error('该接单已被其他订单匹配');
- }
- $offer=ShopPurchase::getOffer($data['tab'])->lock(true)
- // ->where('user_id',$data['offer_id'])
- ->when($tab,function ($querys) use ($tab,$model_id){
- switch ($tab){
- case 1:
- $querys->where('item_id',$model_id);
- break;
- case 2:
- $querys->where('production_id',$model_id);
- break;
- case 3:
- $querys->where('corrdination_id',$model_id);
- break;
- case 4:
- $querys->where('ocea_id',$model_id);
- break;
- }
- })
- ->findOrEmpty();
- if($request['tab']==1){
- if ($offer->item_id != $model['id']) {
- Db::rollback();
- $this->error('该接单不属于此订单');
- }
- }else {
- if ($offer->order_id != $model['id']) {
- Db::rollback();
- $this->error('该接单不属于此订单');
- }
- }
- $model['offer_id']=$data['offer_id'];
- if($data['tab']==1){
- $main=$model->main;
- $main['status']=3;
- $main->save();
- }else{
- $model['status']=3;
- }
- $model->save();
- Db::commit();
- $url = setword($data['tab']+1,$data['id']);
- ShopPurchase::getItem($data['tab'])->where('id',$model['id'])->update(['down_word'=>$url]);
- $this->success('匹配成功');
- }
- /**
- * @Title ("发送留言")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("user_id",desc="发送给的用户id")
- * @Param ("content",desc="内容")
- */
- public function msg_send(Request $request){
- $this->_vali([
- 'id.require'=>'id必须',
- 'user_id.require'=>'用户必须',
- 'tab.require'=>'tab必须',
- 'content.require'=>'tab必须',
- 'content.max:500'=>'内容过长',
- ]);
- $model=ShopPurchase::getQuery($request['tab'])->findOrFail($request['id']);
- $user=DataUser::where('id',$request['user_id'])->findOrFail();
- $msg=DataUserLeaveMessage::create([
- 'uuid'=>$this->uuid()->id,
- 'uuid2'=>$user['id'],
- 'content'=>$request['content'],
- 'type'=>DataUserLeaveMessage::getMsgType($model->getTable()),
- 'link_id'=>$model['id'],
- ]);
- $this->success('发送成功',$msg);
- }
- /**
- * @Title ("留言列表")
- * @Param ("id",desc="订单ID")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("user_id",desc="要查看的用户id")
- * @Returned ("user.headimg",desc="用户头像")
- * @Returned ("merchant.headimg",desc="商家头像")
- * @Returned ("is_mine",desc="是否是自己的留言")
- */
- public function msg_get(Request $request){
- $this->_vali([
- 'id.require'=>'id必须',
- 'tab.require'=>'tab必须',
- ],'get');
- $model=ShopPurchase::getQuery($request['tab'])->findOrFail($request['id']);
- $admin_id = $model['admin_id'];
- $user_id = $request['user_id'];
- $messagelist = DataUserLeaveMessage::mk()
- ->where('type',DataUserLeaveMessage::getMsgType($model->getTable()))
- ->whereRaw("(uuid=$user_id and uuid2=$admin_id) or (uuid2=$user_id and uuid=$admin_id)")
- ->where('link_id',$model['id'])
- ->field('id,uuid,uuid2,content,create_at')
- ->select()->toArray();
- $this->success('成功',$messagelist);
- }
- /**
- * @Title("获取订单配置")
- * @Returned("packing",desc="包装形式数组")
- */
- public function config(){
- $config=[];
- $config['packing']=systemConfig('merchant_config.packing')?:[];
- $this->success('',$config);
- }
- }
|