ShopOcean.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\library\Common;
  4. use app\data\model\DataMerchants;
  5. use app\data\model\ShopOcean as Model;
  6. use app\data\model\DataUser;
  7. use Carbon\Carbon;
  8. use think\admin\Controller;
  9. use app\data\model\SystemUser;
  10. use think\admin\model\SystemConfig;
  11. use think\admin\service\AdminService;
  12. use think\db\Query;
  13. use think\facade\Db;
  14. use think\Request;
  15. /**
  16. * 海运订单管理
  17. * Class Xw
  18. * @package app\admin\controller\ShopOcean
  19. * http://www.zjnk.com/fileserver/News/04b7854f-bb0a-458b-b359-ce948acfea09.JPG
  20. */
  21. class ShopOcean extends Controller
  22. {
  23. /**
  24. * 列表
  25. * @auth true
  26. * @menu true
  27. */
  28. public function index(Request $request){
  29. if(AdminService::getUserId()==10000){
  30. $admin_id = [];
  31. }else{
  32. $admin_id['admin_id']=AdminService::getUserId();
  33. }
  34. $this->title='海运订单管理';
  35. $this->assign('status',\app\data\model\ShopPurchase::getStatus());
  36. $result = Model::mQuery()
  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. ->equal('status')
  44. ->dateBetween('create_time');
  45. // ->layTable();
  46. $this->amount = $result->db()->sum('amount');
  47. $result->page();
  48. }
  49. /**
  50. * 详情
  51. * @auth true
  52. * @menu true
  53. */
  54. public function detail(Request $request,Model $purchase){
  55. DataUser::$copyRealName=true;
  56. $this->assign('row',$purchase
  57. ->with(['merchant','items','offers','offers.user'])
  58. ->where('id',$request['id'])->findOrFail());
  59. $this->fetch('form');
  60. }
  61. /**
  62. * 发布
  63. * @auth true
  64. * @menu true
  65. */
  66. public function add(Request $request,\think\Validate $validate){
  67. $this->title='发布订单';
  68. $this->assign('vo',null);
  69. if($request->isGet()) {
  70. $config = systemConfig('merchant_config.packing')?:[];
  71. $this->assign('config',$config);
  72. $this->fetch();
  73. }else{
  74. $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
  75. if(!$merchant){
  76. $this->error('您不是商家无法发布');
  77. }
  78. $data=$request->post();
  79. $item=$data['item']??[];
  80. foreach ($item as $i){
  81. $make=$validate->check($i,[
  82. 'name'=>['require',],
  83. 'weight'=>['require','integer'],
  84. // 'spec'=>['require',],
  85. // 'number'=>['require','integer'],
  86. // 'standard'=>['require',],
  87. // 'price'=>['require','float'],
  88. ]);
  89. if(!$make){
  90. $this->error('请填写正确的商品信息');
  91. }
  92. }
  93. app()->db->startTrans();
  94. unset($data['item']);
  95. $data['admin_id']=AdminService::getUserId();
  96. $data['form']=implode(',',$data['fm']);
  97. $data['longitude']=$merchant['longitude']??null;
  98. $data['latitude']=$merchant['latitude']??null;
  99. // $data['amount']=min(array_column($item,'price'));
  100. $data['type'] =1;
  101. $order= \app\data\model\ShopOcean::create($data);
  102. $order->items()->saveAll($item);
  103. app()->db->commit();
  104. $this->success('保存成功');
  105. }
  106. }
  107. /**
  108. * 编辑
  109. * @auth true
  110. * @menu true
  111. */
  112. public function edit(Request $request,Model $purchase,\think\Validate $validate){
  113. // $this->title='发布订单';
  114. // $this->assign('vo',null);
  115. if($request->isGet()) {
  116. DataUser::$copyRealName=true;
  117. $config = systemConfig('merchant_config.packing')?:[];
  118. $this->assign('config',$config);
  119. $row = $purchase
  120. ->with(['merchant','items','offers','favourite','ppoffer'])
  121. ->where('id',$request['id'])->findOrFail();
  122. if (!$row['merchant']){
  123. $array = ['company'=>'平台发布'];
  124. $row['merchant'] = $array;
  125. }
  126. // var_dump($row['form']);die;
  127. $row['fm'] = explode(',',$row['form']);
  128. $row['images'] = $row['file'];
  129. if($row['images'] == '' || $row['images'] == null){
  130. $row['images'] = [];
  131. }
  132. $this->assign('row',$row);
  133. $this->fetch('edit');
  134. }else{
  135. $merchant=DataMerchants::getByAdmin(AdminService::getUserId());
  136. if(!$merchant){
  137. $this->error('您不是商家无法发布');
  138. }
  139. $data=$request->post();
  140. $item=$data['item']??[];
  141. foreach ($item as $i){
  142. $make=$validate->check($i,[
  143. 'name'=>['require',],
  144. 'weight'=>['require','integer'],
  145. // 'spec'=>['require',],
  146. // 'number'=>['require','integer'],
  147. // 'standard'=>['require',],
  148. // 'price'=>['require','float'],
  149. ]);
  150. if(!$make){
  151. $this->error('请填写正确的商品信息');
  152. }
  153. }
  154. app()->db->startTrans();
  155. unset($data['item']);
  156. $data['admin_id']=AdminService::getUserId();
  157. $data['form']=implode(',',$data['fm']);
  158. $data['longitude']=$merchant['longitude']??null;
  159. $data['latitude']=$merchant['latitude']??null;
  160. // $data['amount']=min(array_column($item,'price'));
  161. $data['type'] =1;
  162. // $order= \app\data\model\ShopOcean::create($data);
  163. if(!$data['offer_id']){
  164. unset($data['offer_id']);
  165. }
  166. if(isset($data['images'])){
  167. $data['file'] = $data['images'];
  168. }else{
  169. $data['file'] = null;
  170. }
  171. $order=Model::update($data);
  172. $order->items()->saveAll($item);
  173. app()->db->commit();
  174. $this->success('保存成功');
  175. }
  176. }
  177. /**
  178. * 取消订单
  179. * @auth true
  180. * @menu true
  181. */
  182. public function cancellation(Request $request, \app\data\model\ShopOcean $purchase){
  183. $purchase_=$purchase->where('id',$request['id'])->findOrFail();
  184. $purchase_['status']=0;
  185. $purchase_->save();
  186. $this->success('取消成功');
  187. }
  188. }