ShopCoor.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace app\admin\controller;
  3. use app\data\model\DataMerchants;
  4. use app\data\model\ShopCoordination as Model;
  5. use app\data\model\DataUser;
  6. use Carbon\Carbon;
  7. use think\admin\Controller;
  8. use app\data\model\SystemUser;
  9. use think\admin\service\AdminService;
  10. use think\db\Query;
  11. use think\facade\Db;
  12. use think\Request;
  13. /**
  14. * 外协订单管理
  15. * Class Xw
  16. * @package app\admin\controller\ShopCoor
  17. * http://www.zjnk.com/fileserver/News/04b7854f-bb0a-458b-b359-ce948acfea09.JPG
  18. */
  19. class ShopCoor extends Controller
  20. {
  21. /**
  22. * 列表
  23. * @auth true
  24. * @menu true
  25. */
  26. public function index(Request $request){
  27. if(AdminService::getUserId()==10000){
  28. $admin_id = [];
  29. }else{
  30. $admin_id['admin_id']=AdminService::getUserId();
  31. }
  32. $this->title='外协订单管理';
  33. $this->assign('status',\app\data\model\ShopPurchase::getStatus());
  34. Model::mQuery()
  35. ->with(['merchant'])
  36. ->when($request['name'],function (Query $query)use ($request){
  37. $query->hasWhere('merchant',function (Query $query)use ($request){
  38. $query->whereLike('name',"%{$request['name']}%");
  39. });
  40. })->where($admin_id)
  41. ->equal('status')
  42. ->dateBetween('create_time')
  43. ->layTable();
  44. }
  45. /**
  46. * 详情
  47. * @auth true
  48. * @menu true
  49. */
  50. public function detail(Request $request,Model $purchase){
  51. DataUser::$copyRealName=true;
  52. $this->assign('row',$purchase
  53. ->with(['merchant','items','offers','offers.user'])
  54. ->where('id',$request['id'])->findOrFail());
  55. $this->fetch('form');
  56. }
  57. /**
  58. * 发布
  59. * @auth true
  60. * @menu true
  61. */
  62. public function add(Request $request,\think\Validate $validate){
  63. $this->title='发布订单';
  64. $this->assign('vo',null);
  65. if($request->isGet()) {
  66. $this->fetch();
  67. }else{
  68. $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
  69. if(!$merchant){
  70. $this->error('您不是商家无法发布');
  71. }
  72. $data=$request->post();
  73. $item=$data['item']??[];
  74. foreach ($item as $i){
  75. $make=$validate->check($i,[
  76. 'name'=>['require',],
  77. 'spec'=>['require',],
  78. 'number'=>['require','integer'],
  79. // 'enclosure'=>['require',],
  80. // 'price'=>['require','float'],
  81. ]);
  82. if(!$make){
  83. $this->error('请填写正确的商品信息');
  84. }
  85. }
  86. app()->db->startTrans();
  87. unset($data['item']);
  88. $data['admin_id']=AdminService::getUserId();
  89. $data['longitude']=$merchant['longitude']??null;
  90. $data['latitude']=$merchant['latitude']??null;
  91. // $data['amount']=min(array_column($item,'price'));
  92. $data['type'] =1;
  93. $order= \app\data\model\ShopCoordination::create($data);
  94. $order->items()->saveAll($item);
  95. app()->db->commit();
  96. $this->success('保存成功');
  97. }
  98. }
  99. }