ShopProduction.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace app\admin\controller;
  3. use app\data\model\DataMerchants;
  4. use app\data\model\ShopProduction 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\ShopProduction
  17. * http://www.zjnk.com/fileserver/News/04b7854f-bb0a-458b-b359-ce948acfea09.JPG
  18. */
  19. class ShopProduction 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. ->equal('status')
  36. ->dateBetween('create_time')
  37. ->with(['merchant'])
  38. ->when($request['name'],function (Query $query)use ($request){
  39. $query->hasWhere('merchant',function (Query $query)use ($request){
  40. $query->whereLike('name',"%{$request['name']}%");
  41. });
  42. })->where($admin_id)
  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. // 'standard'=>['require',],
  80. // 'price'=>['require','float'],
  81. // 'enclosure'=>['require',],
  82. ]);
  83. if(!$make){
  84. $this->error('请填写正确的商品信息');
  85. }
  86. }
  87. app()->db->startTrans();
  88. unset($data['item']);
  89. $data['admin_id']=AdminService::getUserId();
  90. $data['longitude']=$merchant['longitude']??null;
  91. $data['latitude']=$merchant['latitude']??null;
  92. // $data['amount']=min(array_column($item,'price'));
  93. $data['type'] =1;
  94. // print_r($data);
  95. // exit();
  96. $order= \app\data\model\ShopProduction::create($data);
  97. $order->items()->saveAll($item);
  98. app()->db->commit();
  99. $this->success('保存成功');
  100. }
  101. }
  102. }