123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750 |
- <?php
- namespace app\data\controller\api\auth;
- use app\data\controller\api\Auth;
- use app\data\controller\api\Data;
- use app\data\model\DataCollectionLog;
- use app\data\model\DataPoolTalent;
- use app\data\model\DataRecruitment;
- use app\data\model\DataTeachingKnowledge;
- use app\data\model\DataUser;
- use app\data\model\DataUserApplyJobInfo;
- use app\data\model\DataUserApplyJobInfoChild;
- use app\data\model\DataUserLeaveMessage;
- use app\data\model\DataUserPurchaseAcceptance;
- use app\data\model\ShopCoordination;
- use app\data\model\ShopCoordinationOffer;
- use app\data\model\ShopCoordinationOfferAmount;
- use app\data\model\ShopOcean;
- use app\data\model\ShopOceanOffer;
- use app\data\model\ShopOceanOfferAmount;
- use app\data\model\ShopProduction;
- use app\data\model\ShopProductionOffer;
- use app\data\model\ShopProductionOfferAmount;
- 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 app\data\service\MessageService;
- use think\admin\Storage;
- use think\db\Query;
- use think\exception\HttpResponseException;
- use think\admin\Controller;
- use hg\apidoc\annotation\Title;
- use hg\apidoc\annotation\Method;
- use hg\apidoc\annotation\Param;
- use hg\apidoc\annotation\Header;
- use hg\apidoc\annotation\Returned;
- use think\facade\Db;
- use think\facade\Validate;
- use think\Request;
- /**
- * @Title("用户端采购订单")
- */
- class Purchase extends Auth
- {
- protected $noNeedLogin=['list'];
- /**
- * @Title("列表")
- * @Method("get")
- * @Param ("page",desc="第几页")
- * @Param ("limit",desc="每页几条")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("sort",desc="1按距离排序2按价格排序3按发布时间排序")
- * @Param ("sort_dir",desc="asc正序,desc倒序")
- * @Param ("longitude",desc="当前用户的经度")
- * @Param ("latitude",desc="当前用户的纬度")
- * @Returned ("order_no",desc="订单号")
- * @Returned ("real_name",desc="联系人")
- * @Returned ("mobile",desc="联系方式")
- * @Returned ("post_address",desc="交货地址")
- * @Returned ("post_time",desc="交货时间")
- * @Returned ("create_time",desc="发布时间")
- * @Returned ("images",desc="图片/视频")
- * @Returned ("file",desc="照片/视频")
- * @Returned ("file.type",desc="image或video")
- * @Returned ("file.src",desc="image或video的链接")
- * @Returned ("images",desc="图片视频")
- * @Returned ("images.type",desc="image或video")
- * @Returned ("images.src",desc="image或video的链接")
- * @Returned ("form",desc="包装形式")
- * @Returned ("wharf_to",desc="装货码头")
- * @Returned ("wharf_for",desc="到港码头")
- * @Returned ("standard_tech",desc="生产技术标准")
- * @Returned ("standard_check",desc="生产验收标准")
- * @Returned ("is_fav",desc="是否已收藏")
- * @Returned ("status",desc="1未报价 2已报价 3已匹配'")
- * @Returned ("offer_id",desc="匹配到的接单ID")
- * @Returned ("items.name",desc="产品名称")
- * @Returned ("items.spec",desc="规格")
- * @Returned ("items.number",desc="数量")
- * @Returned ("items.standard",desc="质量标准")
- * @Returned ("items.price",desc="价格")
- * @Returned ("items.enclosure",desc="附件")
- * @Returned ("items.enclosure.filename",desc="附件文件名")
- * @Returned ("items.enclosure.fileurl",desc="附件文件链接")
- * @Returned ("items.enclosure.icon",desc="icon图标")
- * @Returned ("items.weight",desc="重量")
- * @Returned ("items.status",desc="0订单已取消1未报价 2已报价 3已匹配'")
- * @Returned ("merchant.company",desc="公司名")
- * @Returned ("merchant.address",desc="公司地址")
- * @Returned ("user_order",desc="自己的报价信息")
- * @Returned ("user_order.amount",desc="最后一次报价金额")
- * @Returned ("user_order.amounts",desc="历史报价金额数组")
- * @Returned ("user_order.amounts.*.amount",desc="历史报价金额数组金额")
- * @Returned ("user_order.date",desc="货期/月")
- * @Returned ("user_order.desc",desc="描述")
- * @Returned ("user_order.is_have",desc="是否有货")
- * @Returned ("user_order.images",desc="图片")
- * @Returned ("user_order.create_time",desc="报价日期")
- */
- public function list(Request $request)
- {
- $this->_vali([
- 'longitude.require'=>'经度必须',
- 'latitude.require'=>'纬度必须',
- ],'get');
- switch ($request['tab']){
- case 1:
- case 2:
- case 3:
- case 4:
- $query=ShopPurchase::getQuery($request['tab']);
- break;
- default:
- $this->error('类型必须');
- }
- if($request['sort']==1){
- $query
- ->field("*,st_distance(point(`longitude`,`latitude`),point({$request['longitude']},{$request['latitude']})) as distance")
- ->order('distance',$request['sort_dir']);
- }elseif ($request['sort']==2){
- $query->order('amount',$request['sort_dir']);
- }else{
- $query->order('create_time desc');
- }
- $query->with(['merchant','items']);
- $list=$query
- ->paginate($request['limit']?:15)->toArray();
- if($request['tab'] == 1){
- foreach ($list['data'] as $k=>$v){
- $count = count($v['items']);
- $a = '';
- foreach ($v['items'] as $key=>$value){
- if($value['is_matched'] == 1){
- $a++;
- if($a == $count){
- unset($list['data'][$k]);
- }
- }
- }
- }
- $list['data'] = array_values($list['data']);
- }
- $this->success('',$list);
- }
- /**
- * @Title ("收藏取消收藏")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("action",desc="1关注0取消")
- */
- public function favourite(Request $request){
- $this->_vali([
- 'id.require'=>'id必须',
- 'tab.require'=>'tab必须',
- 'tab.in:1,2,3,4'=>'tab有误',
- ]);
- $model=ShopPurchase::getQuery($request['tab'])->findOrFail($request['id']);
- $user=$this->getUser();
- if($request['action']) {
- $model->favourite()->save([
- 'user_id' => $user['id'],
- ]);
- }else{
- $model->favourite()->where('user_id',$user['id'])->delete();
- }
- $this->success('操作成功');
- }
- /**
- * @Title ("采购订单详情")
- * @Param ("id",desc="订单ID")
- * @Returned ("参考列表")
- */
- public function show(Request $request){
- $this->_vali([
- 'id.require'=>'参数有误',
- ],'get');
- $model=ShopPurchase::show()->with(['items','merchant'])->findOrFail($request['id']);
- $user=$this->getUser();
- foreach ($model['items'] as $item){
- $item['user_order']=$item->offers()->with(['amounts'=>function($q)use($user){
- $q->where('user_id',$user['id']);// }])->where('id',$item['offer_id'])
- }])->where('user_id',$user['id'])
- ->find();
- if($item['offer_id']) {
- $item['status'] = 3;
- }else{
- $item['status'] = $item['user_order']?2:1;
- }
- }
- ShopPurchase::is_fav($model,$user);
- $model['huanxinID'] = SystemUser::mk()->where('id',$model['admin_id'])->value('huanxinID');
- $this->success('',$model);
- }
- /**
- * @Title ("生产订单详情")
- * @Param ("id",desc="订单ID")
- * @Returned ("参考列表")
- */
- public function production_show(Request $request){
- $this->_vali([
- 'id.require'=>'参数有误',
- ],'get');
- $model=ShopProduction::show()->with(['items','merchant'])->findOrFail($request['id']);
- $user=$this->getUser();
- $model['user_order']=$model->offers()->with(['amounts'=>function($q)use($user){$q->where('user_id',$user['id']);}])->where('user_id',$user['id'])->find();
- if($model['offer_id']) {
- $model['status'] = 3;
- }else{
- $model['status'] = $model['user_order']?2:1;
- }
- ShopPurchase::is_fav($model,$user);
- $model['huanxinID'] = SystemUser::mk()->where('id',$model['admin_id'])->value('huanxinID');
- $this->success('',$model);
- }
- /**
- * @Title ("海运订单详情")
- * @Param ("id",desc="订单ID")
- * @Returned ("参考列表")
- */
- public function ocean_show(Request $request){
- $this->_vali([
- 'id.require'=>'参数有误',
- ],'get');
- $model=ShopOcean::show()->with(['items','merchant'])->findOrFail($request['id']);
- $user=$this->getUser();
- $model['user_order']=$model->offers()->with(['amounts'=>function($q)use($user){$q->where('user_id',$user['id']);}])->where('user_id',$user['id'])->find();
- if($model['offer_id']) {
- $model['status'] = 3;
- }else{
- $model['status'] = $model['user_order']?2:1;
- }
- ShopPurchase::is_fav($model,$user);
- $model['huanxinID'] = SystemUser::mk()->where('id',$model['admin_id'])->value('huanxinID');
- $this->success('',$model);
- }
- /**
- * @Title ("外协订单详情")
- * @Param ("id",desc="订单ID")
- * @Returned ("参考列表")
- */
- public function coor_show(Request $request){
- $this->_vali([
- 'id.require'=>'参数有误',
- ],'get');
- $model=ShopCoordination::show()->with(['items','merchant'])->findOrFail($request['id']);
- $user=$this->getUser();
- $model['user_order']=$model->offers()->with(['amounts'=>function($q)use($user){$q->where('user_id',$user['id']);}])->where('user_id',$user['id'])->find();
- if($model['offer_id']) {
- $model['status'] = 3;
- }else{
- $model['status'] = $model['user_order']?2:1;
- }
- ShopPurchase::is_fav($model,$user);
- $model['huanxinID'] = SystemUser::mk()->where('id',$model['admin_id'])->value('huanxinID');
- $this->success('',$model);
- }
- protected function checkUnAmount(){
- $user=$this->getUser();
- $unAmount=ShopCoordinationOffer::hasWhere('coordination',function (Query $query) {
- $query->whereNull('offer_id');
- })
- ->whereNull('shop_coordination_offer.amount')
- ->where('user_id',$user['id'])
- ->with(['coordination'])
- ->find();
- if($unAmount){
- $this->error('您有外协订单未报价无法再次接单');
- }
- $unAmount=ShopOceanOffer::hasWhere('ocean',function (Query $query) {
- $query->whereNull('offer_id');
- })->whereNull('shop_ocean_offer.amount')
- ->where('user_id',$user['id'])
- ->with(['ocean'])
- ->find();
- if($unAmount){
- $this->error('您有海运订单未报价无法再次接单');
- }
- $unAmount=ShopProductionOffer::hasWhere('production',function (Query $query) {
- $query->whereNull('offer_id');
- })->whereNull('shop_production_offer.amount')
- ->where('user_id',$user['id'])
- ->with(['production'])
- ->find();
- if($unAmount){
- $this->error('您有生产订单未报价无法再次接单');
- }
- $unAmount=ShopPurchaseOffer::hasWhere('item',function (Query $query){
- $query->whereNull('offer_id');
- })
- ->whereNull('shop_purchase_offer.amount')
- ->where('user_id',$user['id'])
- ->with(['item'])
- ->find();
- if($unAmount){
- $this->error('您有采购订单未报价无法再次接单');
- }
- // $unAmount=ShopCoordinationOffer::whereNull('amount')->where('user_id',$user['id'])->find();
- // if($unAmount){
- // $this->error('您有外协订单未报价无法再次接单');
- // }
- // $unAmount=ShopOceanOffer::whereNull('amount')->where('user_id',$user['id'])->find();
- // if($unAmount){
- // $this->error('您有海运订单未报价无法再次接单');
- // }
- // $unAmount=ShopProductionOffer::whereNull('amount')->where('user_id',$user['id'])->find();
- // if($unAmount){
- // $this->error('您有生产订单未报价无法再次接单');
- // }
- // $unAmount=ShopPurchaseOffer::whereNull('amount')->where('user_id',$user['id'])->find();
- // if($unAmount){
- // $this->error('您有采购订单未报价无法再次接单');
- // }
- }
- /**
- * @Title ("采购订单接单")
- * @Method("post")
- * @Param ("id",desc="子订单ID")
- * @Param ("amount",desc="报价")
- * @Param ("date",desc="货期/月")
- * @Param ("desc",desc="描述")
- * @Param ("is_have",desc="1是0否有货")
- * @Param ("images",desc="图片数组")
- * @Param ("is_edit",desc="1是0否重新报价")
- */
- public function purchase_create(Request $request){
- $data=$this->_vali([
- 'id.require' => '参数有误',
- // 'amount.require' => '报价有误',
- 'amount.float' => '报价有误',
- // 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- // 'images.require' => '参数有误',
- // 'date.require' => '货期必须',
- 'desc.require' => '报价说明必须填写',
- 'desc.max:250' => '报价说明最多250',
- ], 'post');
- if($request['is_edit']){
- $data=$this->_vali([
- 'id.require' => '参数有误',
- 'amount.require' => '报价必须填写',
- 'amount.float' => '报价有误',
- // 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- // 'images.require' => '参数有误',
- // 'date.require' => '货期必须',
- 'desc.require' => '报价说明必须填写',
- 'desc.max:250' => '报价说明最多250',
- ], 'post');
- }else {
- $data = $this->_vali([
- 'id.require' => '参数有误',
- // 'amount.require' => '报价有误',
- 'amount.float' => '报价有误',
- // 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- // 'images.require' => '参数有误',
- // 'date.require' => '货期必须',
- 'desc.require' => '报价说明必须填写',
- 'desc.max:250' => '报价说明最多250',
- ], 'post');
- }
- input('date')?$data['date']=input('date'):'';
- input('is_have')?$data['is_have']=input('is_have'):'';
- $model=ShopPurchaseItem::findOrFail($data['id']);
- $user=$this->getUser();
- if($model['offer_id']){
- $this->error('该订单已匹配无法接单或报价');
- }
- if(!$request['is_edit']) {
- $this->checkUnAmount();
- }
- $offer=$model->offers()->where('user_id',$user['id'])->find();
- if(!$offer) {
- if($request['is_edit']){
- $this->error('没有接单无法报价');
- }
- $data['item_id'] = $data['id'];
- unset($data['id']);
- $data['user_id'] = $user['id'];
- $data['order_id'] = $model['purchase_id'];
- $result = ShopPurchaseOffer::mk()->create($data);
- $offer['id'] = $result->id;
- // $offer = $model->offers()->save([
- // 'user_id' => $user['id'],
- // 'order_id'=>$model['purchase_id'],
- // ] + $data);
- }else{
- $data['id'] = $offer['id'];
- $offer->save($data);
- }
- $offer['amount'] = $data['amount'];
- if(!empty($offer['amount'])){
- ShopPurchaseOfferAmount::create([
- 'user_id'=>$user['id'],
- 'offer_id'=>$offer['id'],
- 'amount'=>$offer['amount'],
- ]);
- if($model->main->status==1){
- $model->main->status=2;
- $model->main->save();
- }
- }
- $this->success('保存成功',$model);
- }
- /**
- * @Title ("生产订单接单")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("amount",desc="报价")
- * @Param ("date",desc="货期/月")
- * @Param ("desc",desc="描述")
- * @Param ("images",desc="图片数组")
- * @Param ("is_edit",desc="是否重新报价")
- */
- public function production_create(Request $request){
- if($request['is_edit']){
- $data=$this->_vali([
- 'id.require' => '参数有误',
- // 'amount.require' => '报价必须',
- 'amount.float' => '报价有误',
- // 'date.require' => '货期必须',
- // 'date.integer' => '货期有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }else {
- $data = $this->_vali([
- 'id.require' => '参数有误',
- 'amount.float' => '报价有误',
- // 'date.require' => '货期必须',
- // 'date.integer' => '货期有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }
- input('date')?$data['date']=input('date'):'';
- $model=ShopProduction::show()->findOrFail($data['id']);
- $user=$this->getUser();
- if($model['offer_id']){
- $this->error('该订单已匹配无法接单或报价');
- }
- if(!$request['is_edit']) {
- $this->checkUnAmount();
- }
- $offer=$model->offers()->where('user_id',$user['id'])->find();
- if(!$offer) {
- if($request['is_edit']){
- $this->error('没有接单无法报价');
- }
- $data['production_id'] = $data['id'];
- unset($data['id']);
- $data['user_id'] = $user['id'];
- $offer = ShopProductionOffer::mk()->create($data);
- // $offer = $model->offers()->save([
- // 'user_id' => $user['id'],
- // ] + $data);
- }else{
- $data['id'] = $offer['id'];
- // file_put_contents("123.txt", json_encode($data,true) . "\n" . "\n", FILE_APPEND);
- $offer->save($data);
- }
- //$offer['amount'] = $data['amount'];
- if(!empty($offer['amount'])){
- ShopProductionOfferAmount::create([
- 'user_id'=>$user['id'],
- 'offer_id'=>$offer['id'],
- 'amount'=>$offer['amount'],
- ]);
- if($model->status==1){
- $model->status=2;
- $model->save();
- }
- }
- $this->success('保存成功',$model);
- }
- /**
- * @Title ("海运订单接单")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("amount",desc="报价")
- * @Param ("desc",desc="描述")
- * @Param ("images",desc="图片数组")
- * @Param ("is_edit",desc="是否重新报价")
- */
- public function ocean_create(Request $request){
- if($request['is_edit']){
- $data=$this->_vali([
- 'id.require' => '参数有误',
- // 'amount.require' => '报价必须',
- 'amount.float' => '报价有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }else {
- $data = $this->_vali([
- 'id.require' => '参数有误',
- 'amount.float' => '报价有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }
- $model=ShopOcean::show()->findOrFail($data['id']);
- $user=$this->getUser();
- if($model['offer_id']){
- $this->error('该订单已匹配无法接单或报价');
- }
- if(!$request['is_edit']) {
- $this->checkUnAmount();
- }
- $offer=$model->offers()->where('user_id',$user['id'])->find();
- if(!$offer) {
- if($request['is_edit']){
- $this->error('没有接单无法报价');
- }
- $data['ocea_id'] = $data['id'];
- unset($data['id']);
- $data['user_id'] = $user['id'];
- $offer = ShopOceanOffer::mk()->create($data);
- // $offer = $model->offers()->save([
- // 'user_id' => $user['id'],
- // ] + $data);
- }else{
- $data['id'] = $offer['id'];
- $offer->save($data);
- }
- if(!empty($offer['amount'])){
- ShopOceanOfferAmount::create([
- 'user_id'=>$user['id'],
- 'offer_id'=>$offer['id'],
- 'amount'=>$offer['amount'],
- ]);
- if($model->status==1){
- $model->status=2;
- $model->save();
- }
- }
- $this->success('保存成功',$model);
- }
- /**
- * @Title ("外协订单接单")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("amount",desc="报价")
- * @Param ("desc",desc="描述")
- * @Param ("images",desc="图片数组")
- * @Param ("is_edit",desc="是否重新报价")
- */
- public function coor_create(Request $request){
- if($request['is_edit']){
- $data=$this->_vali([
- 'id.require' => '参数有误',
- // 'amount.require' => '报价必须',
- 'amount.float' => '报价有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }else {
- $data = $this->_vali([
- 'id.require' => '参数有误',
- 'amount.float' => '报价有误',
- 'desc.require' => '描述必须',
- 'desc.max:250' => '描述最多250',
- 'images.array' => '图片有误',
- 'images.max:9' => '图片最多9张',
- ], 'post');
- }
- $model=ShopCoordination::show()->findOrFail($data['id']);
- $user=$this->getUser();
- if($model['offer_id']){
- $this->error('该订单已匹配无法接单或报价');
- }
- if(!$request['is_edit']) {
- $this->checkUnAmount();
- }
- $offer=$model->offers()->where('user_id',$user['id'])->find();
- if(!$offer) {
- if($request['is_edit']){
- $this->error('没有接单无法报价');
- }
- $data['corrdination_id'] = $data['id'];
- unset($data['id']);
- $data['user_id'] = $user['id'];
- $offer = ShopCoordinationOffer::mk()->create($data);
- // $offer = $model->offers()->save([
- // 'user_id' => $user['id'],
- // ] + $data);
- }else{
- $data['id'] = $offer['id'];
- $offer->save($data);
- }
- if(!empty($offer['amount'])){
- ShopCoordinationOfferAmount::create([
- 'user_id'=>$user['id'],
- 'offer_id'=>$offer['id'],
- 'amount'=>$offer['amount'],
- ]);
- if($model->status==1){
- $model->status=2;
- $model->save();
- }
- }
- $this->success('保存成功',$model);
- }
- /**
- * @Title("接单需求")
- * @Param("page",desc="第几页")
- * @Param("limit",desc="每页数量")
- * @Param("keyword",desc="关键字")
- * @Returned("user",desc="用户对象")
- * @Returned("user.headimg",desc="用户头像")
- * @Returned("user.phone",desc="电话")
- * @Returned("addr",desc="地址")
- * @Returned("description",desc="需求说明")
- * @Returned("username",desc="用户名")
- * @Returned("imgs",desc="图片及资质证件图片,多个以英文逗号隔开")
- */
- public function needs(Request $request){
- $list=DataUserPurchaseAcceptance::with(['user'])
- // ->when($request['keyword'],function (Query $query)use ($request){
- // $query->whereExists(
- // DataUser::whereLike('nickname|real_name',"%{$request['keyword']}%")->where('id',Db::raw(DataUserPurchaseAcceptance::getTable().'.uuid'))->buildSql()
- // );
- // })
- ->when($request['keyword'],function ($query)use ($request){
- $query->whereLike('description',"%{$request['keyword']}%");
- })
- ->where('hidden',1)
- ->where('status',1)
- ->order('id','desc')
- ->paginate($request['limit']?:15);
- foreach ($list as $item){
- $item['username']=$item['user']['nickname']??'-';
- }
- $this->success('',$list);
- }
- /**
- *@Title("接单需求详情")
- *@Param("id",desc="ID")
- */
- public function needs_show(Request $request){
- $show=DataUserPurchaseAcceptance::with(['user'])
- ->where('status',1)
- ->where('id',$request['id'])
- ->findOrFail();
- $show['username']=$show['user']['nickname']??'-';
- $this->success('',$show);
- }
- /**
- * @Title ("发送留言")
- * @Method("post")
- * @Param ("id",desc="订单ID")
- * @Param ("tab",desc="1采购2生产3外协4海运")
- * @Param ("content",desc="内容")
- */
- public function msg_send(Request $request){
- $this->_vali([
- 'id.require'=>'id必须',
- 'tab.require'=>'tab必须',
- 'content.require'=>'tab必须',
- 'content.max:500'=>'内容过长',
- ]);
- $model=ShopPurchase::getQuery($request['tab'])->findOrFail($request['id']);
- /*$msg=$model->msgs()->save([
- 'content'=>$request['content'],
- 'user_id'=>$this->uuid,
- 'm_id' =>$model['admin_id'],
- ]);*/
- $msg=DataUserLeaveMessage::create([
- 'uuid'=>$this->uuid,
- 'uuid2'=>$model['admin_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海运")
- * @Returned ("user.headimg",desc="用户头像")
- * @Returned ("merchant.headimg",desc="商家头像")
- * @Returned ("is_mine",desc="是否是自己的留言")
- */
- public function msg_get(Request $request,DataUserLeaveMessage $message){
- $this->_vali([
- 'id.require'=>'id必须',
- 'tab.require'=>'tab必须',
- ],'get');
- $model=ShopPurchase::getQuery($request['tab'])->findOrFail($request['id']);
- $admin_id = $model['admin_id'];
- $messagelist = DataUserLeaveMessage::mk()
- ->where('type',DataUserLeaveMessage::getMsgType($model->getTable()))
- ->where('link_id',$model['id'])
- ->whereRaw("(uuid=$this->uuid and uuid2=$admin_id) or (uuid2=$this->uuid and uuid=$admin_id)")
- ->with(['user'=>function($query){
- $query->field('id,nickname,headimg');
- }])
- ->field('id,uuid,uuid2,content,create_at')
- ->select();
- // echo DataUserLeaveMessage::getLastSql();die;
- $this->success('成功',$messagelist);
- }
- }
|