OrderController.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  1. <?php
  2. namespace app\index\controller;
  3. use think\exception\ValidateException;
  4. use app\model\Cart;
  5. use app\model\Order;
  6. use app\model\OrderCount;
  7. use app\model\Member;
  8. use app\model\Config;
  9. use app\model\OrderStatus;
  10. use app\model\OrderHistory;
  11. use app\model\Goods;
  12. use app\model\TuanFound;
  13. use app\model\Paymethod;
  14. use app\model\OrderStaff;
  15. use app\model\OrderTuanzhang;
  16. use app\model\Address;
  17. use app\model\Category;
  18. use app\model\TransportExtend;
  19. use app\model\UuidRelation;
  20. use app\model\Technical;
  21. use app\model\Agent;
  22. use app\model\RegisterField;
  23. use app\model\Store;
  24. use app\model\Operatingcity;
  25. use app\model\Incomelog;
  26. use app\model\Geocoder;
  27. use app\model\OrderImage;
  28. use app\model\OrderAddress;
  29. use app\model\Users;
  30. use app\model\Area;
  31. use app\model\MessageMini;
  32. use app\model\MessageMp;
  33. class OrderController extends Base
  34. {
  35. public function list()
  36. {
  37. $uuid = UuidRelation::getuuid(UID(), 'technical');
  38. $uid = UID();
  39. $weid = weid();
  40. $status = input('post.status', '', 'serach_in');
  41. $admin = input('post.admin', '', 'serach_in');
  42. $technical = input('post.technical', '', 'serach_in');
  43. $publicorder = input('post.publicorder', '', 'serach_in');
  44. $store = input('post.store', '', 'serach_in');
  45. $ptype = input('post.ptype', '', 'serach_in');
  46. $is_times = input('post.is_times', '', 'serach_in');
  47. if (empty($ptype)) {
  48. $ptype = 1;
  49. }
  50. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  51. $query->with(['paymethod']);
  52. $Membermob = new Member;
  53. $Member = $Membermob->getUserByWechat();
  54. if ($admin == 1) {
  55. } elseif ($store == 1) {
  56. $data = Store::where(['uid' => UID()])->find();
  57. if ($data) {
  58. $data = $data->toArray();
  59. $query->where('sid', $data['id']);
  60. }
  61. } elseif ($technical == 1) {
  62. if (!empty($uuid) && !empty($uid)) {
  63. OrderStaff::where('uid', $uid)->update(['uuid' => $uuid]);
  64. }
  65. $withJoin = [
  66. 'staff' => ['order_id', 'uuid', 'title', 'end_time', 'begin_time'],
  67. ];
  68. $query->withJoin($withJoin, 'left');
  69. $query->where(['staff.uuid' => $uuid]);
  70. } elseif ($publicorder == 1) {
  71. return $this->publicorder();
  72. } else {
  73. $query->where(['uid' => $Member['id']]);
  74. }
  75. if (!empty($is_times)) {
  76. $query->where('is_times', $is_times);
  77. }
  78. if (!empty($status)) {
  79. $query->where('order_status_id', $status);
  80. }
  81. $orderList = $query->order('id desc')->select()->toArray();
  82. //var_dump($query->getLastsql());
  83. $orderList = Order::setOrderList($orderList);
  84. $data["orderList"] = $orderList;
  85. //$data["amountLogistics"] = $amountLogistics;
  86. $data["isNeedLogistics"] = 1;
  87. $data['is_agent'] = Agent::is_agent($Member['id']);
  88. return $this->json(['data' => $data]);
  89. }
  90. public function myorder()
  91. {
  92. $weid = weid();
  93. $ptype = input('post.ptype', '', 'serach_in');
  94. $status = input('post.status', '', 'serach_in');
  95. $currentTab = input('post.currentTab', '', 'serach_in');
  96. if (empty($status) && !empty($currentTab)) {
  97. $OrderStatus = OrderStatus::listname($ptype);
  98. $status = $OrderStatus[$currentTab]['id'];
  99. }
  100. $ispoints = input('post.ispoints', '', 'serach_in');
  101. $is_times = input('post.is_times', '', 'serach_in');
  102. if (empty($ptype)) {
  103. $ptype = 1;
  104. }
  105. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  106. $query->with(['paymethod']);
  107. $Membermob = new Member;
  108. $Member = $Membermob->getUserByWechat();
  109. $query->where(['uid' => $Member['id']]);
  110. if (!empty($ispoints)) {
  111. $query->where('payment_code', 'points_pay');
  112. }
  113. if (!empty($is_times)) {
  114. $query->where('is_times', $is_times);
  115. }
  116. if (!empty($status)) {
  117. $query->where('order_status_id', $status);
  118. }
  119. OrderCount::upread($Member['id'], $status);
  120. $res = $query->order('id desc')
  121. ->paginate(getpage())
  122. ->toArray();
  123. //var_dump($query->getLastsql());
  124. $res['data'] = Order::setOrderList($res['data']);
  125. $data['data'] = $res;
  126. return $this->json($data);
  127. }
  128. public function technicalorder()
  129. {
  130. $Technical = Technical::getInfobyuid(UID());
  131. if ($Technical['status'] != 1) {
  132. throw new ValidateException("您不是师傅!");
  133. }
  134. $uuid = UuidRelation::getuuid(UID(), 'technical');
  135. $uid = UID();
  136. $weid = weid();
  137. $ptype = input('post.ptype', '', 'serach_in');
  138. $status = input('post.status', '', 'serach_in');
  139. $currentTab = input('post.currentTab', '', 'serach_in');
  140. if (empty($status) && !empty($currentTab)) {
  141. $OrderStatus = OrderStatus::listname($ptype);
  142. $status = $OrderStatus[$currentTab]['id'];
  143. }
  144. if (empty($ptype)) {
  145. $ptype = 2;
  146. }
  147. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  148. if (!empty($status)) {
  149. $query->where('order_status_id', $status);
  150. }
  151. if (!empty($uuid) && !empty($uid)) {
  152. OrderStaff::where('uid', $uid)->update(['uuid' => $uuid]);
  153. }
  154. $withJoin = [
  155. 'staff' => ['order_id', 'uuid', 'title', 'end_time', 'begin_time'],
  156. ];
  157. $query->withJoin($withJoin, 'left');
  158. $query->where(['staff.uuid' => $uuid]);
  159. $res = $query->order('id desc')
  160. ->paginate(getpage())
  161. ->toArray();
  162. $res['data'] = Order::setOrderList($res['data']);
  163. $data['data'] = $res;
  164. return $this->json($data);
  165. }
  166. public function storeorder()
  167. {
  168. $Store = Store::getInfobyuid(UID());
  169. if ($Store['status'] != 1) {
  170. throw new ValidateException("您不是商家!");
  171. }
  172. $weid = weid();
  173. $ptype = input('post.ptype', '', 'serach_in');
  174. $status = input('post.status', '', 'serach_in');
  175. $currentTab = input('post.currentTab', '', 'serach_in');
  176. if (empty($status) && !empty($currentTab)) {
  177. $OrderStatus = OrderStatus::listname($ptype);
  178. $status = $OrderStatus[$currentTab]['id'];
  179. }
  180. if (empty($ptype)) {
  181. $ptype = 2;
  182. }
  183. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  184. if (!empty($status)) {
  185. $query->where('order_status_id', $status);
  186. }
  187. if ($Store) {
  188. $query->where('sid', $Store['id']);
  189. }
  190. $res = $query->order('id desc')
  191. ->paginate(getpage())
  192. ->toArray();
  193. $res['data'] = Order::setOrderList($res['data']);
  194. $data['data'] = $res;
  195. return $this->json($data);
  196. }
  197. public function operatingcityorder()
  198. {
  199. $Operatingcity = Operatingcity::getInfobyuid(UID());
  200. if ($Operatingcity['status'] != 1) {
  201. throw new ValidateException("您不是城市代码!");
  202. }
  203. $weid = weid();
  204. $ptype = input('post.ptype', '', 'serach_in');
  205. $status = input('post.status', '', 'serach_in');
  206. $currentTab = input('post.currentTab', '', 'serach_in');
  207. if (empty($status) && !empty($currentTab)) {
  208. $OrderStatus = OrderStatus::listname($ptype);
  209. $status = $OrderStatus[$currentTab]['id'];
  210. }
  211. if (empty($ptype)) {
  212. $ptype = 2;
  213. }
  214. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  215. if (!empty($status)) {
  216. $query->where('order_status_id', $status);
  217. }
  218. $uuid = UuidRelation::getuuid(UID(), 'operatingcity');
  219. $Operatingcitydata = Operatingcity::where(['uuid' => $uuid])->find();
  220. if ($Operatingcitydata) {
  221. $Operatingcitydata = $Operatingcitydata->toArray();
  222. if (empty($Operatingcitydata['areatype'])) {
  223. $Operatingcitydata['areatype'] = 3;
  224. }
  225. if ($Operatingcitydata['areatype'] == 3) {
  226. $query->where('shipping_district_name', $Operatingcitydata['district_name']);
  227. } elseif ($Operatingcitydata['areatype'] == 2) {
  228. $query->where('shipping_city_name', $Operatingcitydata['city_name']);
  229. } elseif ($Operatingcitydata['areatype'] == 1) {
  230. $query->where('shipping_province_name', $Operatingcitydata['province_name']);
  231. }
  232. }
  233. $res = $query->order('id desc')
  234. ->paginate(getpage())
  235. ->toArray();
  236. $res['data'] = Order::setOrderList($res['data']);
  237. $data['data'] = $res;
  238. return $this->json($data);
  239. }
  240. public function adminorder()
  241. {
  242. $user = Users::getadminbyopenid();
  243. if (!$user) {
  244. throw new ValidateException("您不是管理员!");
  245. }
  246. $weid = weid();
  247. $ptype = input('post.ptype', '', 'serach_in');
  248. $status = input('post.status', '', 'serach_in');
  249. $currentTab = input('post.currentTab', '', 'serach_in');
  250. if (empty($status) && !empty($currentTab)) {
  251. $OrderStatus = OrderStatus::listname($ptype);
  252. $status = $OrderStatus[$currentTab]['id'];
  253. }
  254. if (empty($ptype)) {
  255. $ptype = 2;
  256. }
  257. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  258. if (!empty($status)) {
  259. $query->where('order_status_id', $status);
  260. }
  261. $res = $query->order('id desc')
  262. ->paginate(getpage())
  263. ->toArray();
  264. $res['data'] = Order::setOrderList($res['data']);
  265. $data['data'] = $res;
  266. return $this->json($data);
  267. }
  268. public function teamorder()
  269. {
  270. $weid = weid();
  271. $status = input('post.status', '', 'serach_in');
  272. $ptype = input('post.ptype', '', 'serach_in');
  273. $Membermob = new Member;
  274. $Member = $Membermob->getUserByWechat();
  275. $where['weid'] = $weid;
  276. $where['uid'] = $Member['id'];
  277. $orderids = Incomelog::where($where)->column('order_id');
  278. $query = Order::where(['weid' => $weid]);
  279. if (!empty($ptype)) {
  280. $query->where('ptype', $ptype);
  281. }
  282. if (!empty($status)) {
  283. $query->where('order_status_id', $status);
  284. }
  285. $query->where('id', 'in', $orderids);
  286. //$uidlist = Member::getDepart($Member['id']);
  287. //$query->where(['uid' => $uidlist]);
  288. $res = $query->order('id desc')
  289. ->paginate(getpage())
  290. ->toArray();
  291. $res['data'] = Order::setOrderList($res['data']);
  292. $data['data'] = $res;
  293. return $this->json($data);
  294. }
  295. public function publicorder()
  296. {
  297. $identity = input('post.identity', '', 'serach_in');
  298. $from['longitude'] = input('post.longitude', '', 'serach_in');
  299. $from['latitude'] = input('post.latitude', '', 'serach_in');
  300. $weid = weid();
  301. $ptype = input('post.ptype', '', 'serach_in');
  302. if (empty($ptype)) {
  303. $ptype = 2;
  304. }
  305. $query = Order::where(['weid' => $weid, 'ptype' => $ptype]);
  306. $uuid = UuidRelation::getuuid(UID(), $identity);
  307. if ($identity == 'technical') {
  308. $technicalConfig = Config::getconfig('technical');
  309. if ($technicalConfig['is_pickuporder'] != 1) {
  310. return $this->json(['errno' => 1, 'msg' => '系统没有开启抢单功能!']);
  311. }
  312. $Technicaldata = Technical::where('uuid', $uuid)->find();
  313. if (!empty($Technicaldata)) {
  314. $Configdata = Config::getconfig();
  315. if (empty($Configdata['locationscope'])) {
  316. $Configdata['locationscope'] = 3;
  317. }
  318. if ($Configdata['locationscope'] == 3 && $Technicaldata->district_name) {
  319. $city = $Technicaldata->district_name;
  320. $query->where(['shipping_district_name' => $Technicaldata->district_name]);
  321. } else if ($Configdata['locationscope'] == 2 && $Technicaldata->city_name) {
  322. $city = $Technicaldata->city_name;
  323. $query->where(['shipping_city_name' => $Technicaldata->city_name]);
  324. } else if ($Configdata['locationscope'] == 1 && $Technicaldata->province_name) {
  325. $city = $Technicaldata->province_name;
  326. $query->where(['shipping_province_name' => $Technicaldata->province_name]);
  327. }
  328. }
  329. if (empty($city)) {
  330. $query->where(['shipping_city_name' => '-1']);
  331. }
  332. }
  333. $query->where(['order_status_id' => 2]);
  334. if ($identity == 'technical') {
  335. if ($Technicaldata->cate_ids) {
  336. $query->where(['order_status_id' => 2]);
  337. $query->where('cate_ids', 'in', Category::getidssonid($Technicaldata->cate_ids));
  338. }
  339. }
  340. $res = $query->order('id desc')
  341. ->paginate(getpage())
  342. ->toArray();
  343. //var_dump($query->getLastsql());
  344. $res['data'] = Order::setOrderList($res['data']);
  345. if ($from['longitude'] && $from['latitude']) {
  346. foreach ($res['data'] as &$vo) {
  347. $addressdata = OrderAddress::where(['order_id' => $vo['id'], 'ptype' => 1])->find();
  348. if (empty($addressdata)) {
  349. $addressdata = Address::find($vo['address_id']);
  350. }
  351. if (!empty($addressdata)) {
  352. $addressdata = $addressdata->toArray();
  353. $to1['longitude'] = $addressdata['longitude'];
  354. $to1['latitude'] = $addressdata['latitude'];
  355. if ($to1['longitude'] && $to1['latitude']) {
  356. $vo['realdistance'] = Geocoder::get_distance($from, $to1);
  357. }
  358. }
  359. if ($vo['is_errands'] == 1) {
  360. $takeaddressdata = OrderAddress::where(['order_id' => $vo['id'], 'ptype' => 2])->find();
  361. if (empty($takeaddressdata)) {
  362. $takeaddressdata = Address::find($vo['take_address_id']);
  363. }
  364. if (!empty($takeaddressdata)) {
  365. $takeaddressdata = $takeaddressdata->toArray();
  366. $to2['longitude'] = $takeaddressdata['longitude'];
  367. $to2['latitude'] = $takeaddressdata['latitude'];
  368. if ($to2['longitude'] && $to2['latitude']) {
  369. $vo['takerealdistance'] = Geocoder::get_distance($from, $to2);
  370. }
  371. }
  372. }
  373. }
  374. }
  375. $data['data'] = $res;
  376. //兼容旧版
  377. $data['data']["orderList"] = $res['data'];
  378. return $this->json($data);
  379. }
  380. public function detail()
  381. {
  382. $id = input('get.id', '', 'serach_in');
  383. $data = Order::order_info($id);
  384. if (!empty($data['orderInfo']['cat_id'])) {
  385. $data['orderInfo']['cateMap']['image'] = Category::getImage($data['orderInfo']['cat_id']);
  386. } else {
  387. foreach ($data['goods'] as &$vo) {
  388. $vo['goods']['image'] = toimg($vo['goods']['image']);
  389. }
  390. }
  391. if ($data['orderInfo']['additional'] > 0 && $data['orderInfo']['additional_pay_time'] == 0) {
  392. $tmplIds = Config::getconfig('subscribemessage');
  393. $data['tmplIds'][] = $tmplIds['complete_tpl'];
  394. }
  395. if ($data['orderInfo']['is_errands'] == 1) {
  396. $takeaddressdata = OrderAddress::where(['order_id' => $id, 'ptype' => 2])->find();
  397. if (empty($takeaddressdata)) {
  398. $takeaddressdata = Address::find($data['orderInfo']['take_address_id']);
  399. }
  400. if (!empty($takeaddressdata)) {
  401. $takeaddressdata = $takeaddressdata->toArray();
  402. $data['orderInfo']['take_address'] = $takeaddressdata;
  403. }
  404. }
  405. return $this->json(['data' => $data]);
  406. }
  407. public function countdown()
  408. {
  409. $id = input('get.id', '', 'serach_in');
  410. $Orderdata = Order::order_info($id);
  411. $data['Orderdata'] = $Orderdata;
  412. $data['time_1'] = floor((time() - $Orderdata['orderInfo']['start_time']) / 60);
  413. $data['start_time'] = date('Y-m-d H:i:s', $Orderdata['orderInfo']['start_time']);
  414. $data['time_amount'] = ($Orderdata['goods'][0]['time_amount'] * 60) - (time() - $Orderdata['orderInfo']['start_time']);
  415. return $this->json(['data' => $data]);
  416. }
  417. public function errandscreate()
  418. {
  419. $ordermod = new Order;
  420. $payment = input('post.paymentType', '', 'serach_in');
  421. $address_id = input('post.address_id', '', 'serach_in');
  422. $take_address_id = input('post.take_address_id', '', 'serach_in');
  423. if (empty($address_id)) {
  424. return $this->json(['errno' => 1, 'msg' => '请填写收件地址']);
  425. }
  426. if (empty($take_address_id)) {
  427. return $this->json(['errno' => 1, 'msg' => '请填写取件地址']);
  428. }
  429. $remark = input('post.remark', '', 'serach_in');
  430. $distance = input('post.distance', '', 'serach_in');
  431. $amountTotle = input('post.amountTotle', '', 'serach_in');
  432. $order['distance'] = $distance;
  433. $order['total'] = $amountTotle;
  434. $order['number'] = 1;
  435. //支付方式
  436. if (!empty($payment)) {
  437. $order['payment_code'] = $payment;
  438. $paymentdata = Paymethod::where(['code' => $payment, 'weid' => weid()])->find();
  439. $order['pay_method_id'] = $paymentdata->id;
  440. }
  441. $order['address_id'] = $address_id;
  442. $order['take_address_id'] = $take_address_id;
  443. $order['remark'] = $remark;
  444. $order['uid'] = UID();
  445. $ordermod = new Order;
  446. $data = $ordermod->add_order($order);
  447. return $this->json(['data' => $data]);
  448. }
  449. public function create()
  450. {
  451. $uid = UID();
  452. $ordermod = new Order;
  453. $payment = input('post.paymentType', '', 'serach_in');
  454. $cartid = input('post.cartid', '', 'serach_in');
  455. $msid = input('post.msid', '', 'serach_in');
  456. $tuanid = input('post.tuanid', '', 'serach_in');
  457. $jointuanid = input('post.jointuanid', '', 'serach_in');
  458. $deliverymode = input('post.deliverymode', '', 'serach_in');
  459. if (!empty($tuanid) && empty($jointuanid)) {
  460. $jointuanid = TuanFound::getTuanJoinTuanId($tuanid);
  461. }
  462. $technicalId = input('post.technicalId', '', 'serach_in');
  463. if ($technicalId == 'undefined') {
  464. $technicalId = '';
  465. }
  466. $tz_uuid = input('post.tz_uuid', '', 'serach_in');
  467. $tz_id = (int) input('post.tz_id', '', 'serach_in');
  468. if ($tz_uuid == 'undefined') {
  469. $tz_uuid = '';
  470. }
  471. $sid = input('post.sid/d');
  472. $address_id = input('post.address_id', '', 'serach_in');
  473. if ($address_id == 'undefined') {
  474. $address_id = '';
  475. }
  476. $remark = input('post.remark', '', 'serach_in');
  477. $shipping = input('post.shipping', '', 'serach_in');
  478. $couponId = input('post.couponId', '', 'serach_in');
  479. $goods_id = input('post.goodsId', '', 'serach_in');
  480. $otype = input('post.otype', '', 'serach_in');
  481. if ($otype == 'undefined') {
  482. $otype = 0;
  483. }
  484. $cat_id = input('post.cat_id', '', 'serach_in');
  485. $total = input('post.total', '', 'serach_in');
  486. $sku = input('post.sku', '', 'serach_in');
  487. $is_PayPoints = input('post.is_PayPoints', '', 'serach_in');
  488. $number = input('post.number', '', 'serach_in');
  489. $orderimage = input('post.orderimage', '', 'serach_in');
  490. $is_skumore = input('post.is_skumore', '', 'serach_in');
  491. $skumore = json_decode(input('post.skumore'), true);
  492. $combination_ids = input('post.combination_ids', '', 'serach_in');
  493. $servicetime = input('post.servicetime', '', 'serach_in');
  494. $is_times = input('post.is_times', '', 'serach_in');
  495. //加空判定
  496. if (!empty($servicetime)) {
  497. $servicetime = explode(' ', $servicetime);
  498. if (!empty($servicetime[1])) {
  499. $timetmp = explode('-', $servicetime[1]);
  500. }
  501. $order['begin_time'] = strtotime($servicetime[0] . ' ' . $timetmp[0]);
  502. $order['end_time'] = strtotime($servicetime[0] . ' ' . $timetmp[1]);
  503. }
  504. $order['is_times'] = $is_times;
  505. $order['combination_ids'] = $combination_ids;
  506. $order['cartid'] = $cartid;
  507. $order['sid'] = $sid;
  508. if (empty($order['sid']) && !empty($tz_id)) {
  509. $order['sid'] = Store::getidbytzid($tz_id);
  510. }
  511. $order['couponId'] = $couponId;
  512. $order['goods_id'] = $goods_id;
  513. $order['deliverymode'] = $deliverymode;
  514. $order['otype'] = (int) $otype;
  515. $order['total'] = $total;
  516. $order['msid'] = $msid;
  517. $order['tuanid'] = $tuanid;
  518. $order['jointuanid'] = $jointuanid;
  519. $order['sku'] = $sku;
  520. $order['cat_id'] = $cat_id;
  521. $order['is_skumore'] = $is_skumore;
  522. $order['skumore'] = $skumore;
  523. $order['number'] = $number;
  524. $order['address_id'] = $address_id;
  525. $order['technicalId'] = $technicalId;
  526. $order['remark'] = $remark;
  527. $order['is_PayPoints'] = $is_PayPoints;
  528. $order['uid'] = $uid;
  529. //需要配送的
  530. if (!empty($shipping)) {
  531. $order['shipping_method'] = '快递';
  532. } else {
  533. $order['shipping_method'] = '';
  534. }
  535. if (empty($order['address_id']) && empty($order['sid']) && empty($tz_uuid) && $deliverymode != 4) {
  536. throw new ValidateException('请先设置您的地址');
  537. }
  538. //支付方式
  539. if (!empty($payment)) {
  540. $order['payment_code'] = $payment;
  541. $paymentdata = Paymethod::where(['code' => $payment, 'weid' => weid()])->find();
  542. $order['pay_method_id'] = $paymentdata->id;
  543. }
  544. //var_dump($order);
  545. $data = $ordermod->add_order($order);
  546. if ($data['errno'] == 1) {
  547. throw new ValidateException($data['msg']);
  548. }
  549. //图片
  550. if ($data['id']) {
  551. OrderImage::where('order_id', $data['id'])->delete();
  552. if (!empty($orderimage)) {
  553. foreach (explode(',', $orderimage) as $image) {
  554. OrderImage::create([
  555. 'order_id' => (int) $data['id'],
  556. 'weid' => weid(),
  557. 'image' => $image
  558. ]);
  559. }
  560. }
  561. if (!empty($technicalId)) {
  562. $order_staff['order_id'] = $data['id'];
  563. $order_staff['uuid'] = $technicalId;
  564. $order_staff['uid'] = $uid;
  565. $order_staff['begin_time'] = $order['begin_time'];
  566. $order_staff['end_time'] = $order['end_time'];
  567. OrderStaff::addstaff($order_staff);
  568. }
  569. if (!empty($tz_uuid)) {
  570. $order_tuanzhang['order_id'] = $data['id'];
  571. $order_tuanzhang['uuid'] = $tz_uuid;
  572. $order_tuanzhang['uid'] = $uid;
  573. OrderTuanzhang::addtuanzhang($order_tuanzhang);
  574. }
  575. }
  576. return $this->json(['data' => $data]);
  577. }
  578. public function yuyuetime()
  579. {
  580. $id = input('post.id', '', 'intval');
  581. $timestype = input('post.timestype', '', 'serach_in');
  582. $timesdate = input('post.timesdate', '', 'serach_in');
  583. $servicetime = input('post.servicetime', '', 'serach_in');
  584. if (!empty($servicetime)) {
  585. $servicetime = explode(' ', $servicetime);
  586. if (!empty($servicetime[1])) {
  587. $timetmp = explode('-', $servicetime[1]);
  588. }
  589. $order['begin_time'] = strtotime($servicetime[0] . ' ' . $timetmp[0]);
  590. $order['end_time'] = strtotime($servicetime[0] . ' ' . $timetmp[1]);
  591. }
  592. $order['timestype'] = $timestype;
  593. $order['timesdate'] = $timesdate;
  594. $order['id'] = $id;
  595. Order::update($order);
  596. $orderinfo = Order::find($id);
  597. if (!empty($orderinfo)) {
  598. $orderinfo = $orderinfo->toArray();
  599. $timesmum = $orderinfo['timesmum'];
  600. $timesused = OrderStaff::timesused($orderinfo['id']);
  601. $timesmum = $timesmum - $timesused;
  602. if ($timesmum > 0) {
  603. OrderStaff::where(['order_id' => $id, 'is_complete' => 0])->delete();
  604. if ($timestype == 0) {
  605. $iii = 7;
  606. } else {
  607. $iii = 30;
  608. }
  609. for ($i = 0; $i < $timesmum; $i++) {
  610. OrderStaff::create([
  611. 'order_id' => $id,
  612. 'uid' => UID(),
  613. 'yue_begin_time' => strtotime("+" . $i * $iii . " day", $order['begin_time']),
  614. 'yue_end_time' => strtotime("+" . $i * $iii . " day", $order['end_time'])
  615. ]);
  616. }
  617. }
  618. }
  619. return $this->json(['data' => $data]);
  620. }
  621. public function close()
  622. {
  623. $this->cancel();
  624. }
  625. public function cancel()
  626. {
  627. $orderid = input('post.orderid', '', 'serach_in');
  628. Order::cancel_order($orderid);
  629. $data['orderid'] = $orderid;
  630. return $this->json(['data' => $data]);
  631. }
  632. public function receiving()
  633. {
  634. $orderid = input('post.orderid', '', 'serach_in');
  635. Order::receiving($orderid);
  636. $data['orderid'] = $orderid;
  637. return $this->json(['data' => $data]);
  638. }
  639. public function additional()
  640. {
  641. $orderid = input('post.orderid', '', 'serach_in');
  642. $additional = input('post.additional', '', 'serach_in');
  643. $order['additional'] = $additional;
  644. Order::where('id', $orderid)->update($order);
  645. $order_info = Order::find($orderid);
  646. if (!empty($order_info)) {
  647. $order_info = $order_info->toArray();
  648. }
  649. MessageMini::sendMiniItional($order_info);
  650. return $this->json(['data' => $data]);
  651. }
  652. public function complete()
  653. {
  654. $orderid = input('post.orderid', '', 'serach_in');
  655. try {
  656. $data = Order::complete($orderid);
  657. } catch (\Exception $e) {
  658. throw new ValidateException($e->getMessage());
  659. }
  660. return $this->json(['data' => $data]);
  661. }
  662. public function start()
  663. {
  664. $orderid = input('post.orderid', '', 'serach_in');
  665. try {
  666. $data = Order::start($orderid);
  667. } catch (\Exception $e) {
  668. throw new ValidateException($e->getMessage());
  669. }
  670. return $this->json(['data' => $data]);
  671. }
  672. function staff()
  673. {
  674. $id = input('post.id', '', 'intval');
  675. $uuid = input('post.uuid', '', 'serach_in');
  676. $identity = input('post.identity', '', 'serach_in');
  677. if (empty($uuid)) {
  678. $uuid = UuidRelation::getuuid(UID(), $identity);
  679. $msg = '接单';
  680. } else {
  681. $msg = '派单';
  682. $is_distribution = 1;
  683. }
  684. $orderInfo = Order::find($id);
  685. if (!empty($orderInfo)) {
  686. $orderInfo = $orderInfo->toArray();
  687. if ($orderInfo['order_status_id'] == 2) {
  688. $order_history['order_status_id'] = 3;
  689. $orderup['order_status_id'] = 3;
  690. }
  691. try {
  692. $order_history['order_id'] = $orderInfo['id'];
  693. $order_history['remark'] = $msg;
  694. $order_history['notify'] = 1;
  695. OrderHistory::create($order_history);
  696. if ($uuid) {
  697. if ($identity == "technical") {
  698. $order_staff['order_id'] = $orderInfo['id'];
  699. $order_staff['uuid'] = $uuid;
  700. $order_staff['yue_begin_time'] = $orderInfo['begin_time'];
  701. $order_staff['yue_end_time'] = $orderInfo['end_time'];
  702. OrderStaff::addstaff($order_staff);
  703. MessageMini::sendMiniStaff($orderInfo);
  704. if (!empty($is_distribution)) {
  705. MessageMp::distribution($uuid, $orderInfo);
  706. }
  707. } elseif ($identity == "store") {
  708. $Store = Store::where(['uuid' => $uuid])->find();
  709. if (!empty($Store)) {
  710. $orderup['sid'] = $Store->id;
  711. }
  712. }
  713. }
  714. $orderup['id'] = $orderInfo['id'];
  715. order::update($orderup);
  716. $orderup['uid'] = $orderInfo['uid'];
  717. OrderCount::createuserdata($orderup);
  718. } catch (\Exception $e) {
  719. throw new ValidateException($e->getMessage());
  720. }
  721. }
  722. return $this->json(['msg' => $msg . '成功']);
  723. }
  724. //付款凭证上传
  725. public function offlinepayment()
  726. {
  727. $orderid = input('post.orderid', '', 'serach_in');
  728. $img = input('post.image', '', 'serach_in');
  729. $remark = input('post.remark', '', 'serach_in');
  730. $order = new Order;
  731. $insert = $order->OfflinepaymentTap($orderid, $img, $remark);
  732. if ($insert) {
  733. Order::offline_order($orderid);
  734. $errno = 0;
  735. $message = '提交成功,请等待管理员审核!';
  736. return $this->json(['message' => $message, 'data' => $data]);
  737. } else {
  738. $errno = 1;
  739. $message = '提交失败,请重新尝试!';
  740. return $this->json(['message' => $message, 'data' => $data]);
  741. }
  742. }
  743. public function custom()
  744. {
  745. $id = input('post.id', '', 'intval');
  746. if (empty($id)) {
  747. $id = input('post.orderid', '', 'serach_in');
  748. }
  749. $registerfield['fields'] = json_decode(input('post.registerfield'), true);
  750. $data = RegisterField::fieldToData($registerfield)['data'];
  751. Order::where('id', $id)->update(['customtext' => $data['customtext']]);
  752. $msg = '提交成功';
  753. return $this->json(['msg' => $msg, 'data' => $data]);
  754. }
  755. public function taketotal()
  756. {
  757. $address_id = input('post.address_id', '', 'serach_in');
  758. $take_address_id = input('post.take_address_id', '', 'serach_in');
  759. $data = Address::geterrands($address_id, $take_address_id);
  760. return $this->json(['data' => $data]);
  761. }
  762. public function total()
  763. {
  764. $charge = 0;
  765. $cartid = input('post.cartid', '', 'serach_in');
  766. $msid = input('post.msid', '', 'serach_in');
  767. $tuanid = input('post.tuanid', '', 'serach_in');
  768. $ptype = input('post.ptype', '', 'serach_in');
  769. $address_id = input('post.address_id', '', 'serach_in');
  770. $technicalId = input('post.technicalId', '', 'serach_in');
  771. if ($technicalId == 'undefined') {
  772. $technicalId = '';
  773. }
  774. if (empty($cartid)) {
  775. $goods_id = input('post.goodsId', '', 'serach_in');
  776. $sku = input('post.sku', '', 'serach_in');
  777. $number = input('post.number', '', 'serach_in');
  778. $is_skumore = input('post.is_skumore', '', 'serach_in');
  779. $skumore = json_decode(input('post.skumore'), true);
  780. $Goods = new Goods;
  781. $buygoods = $Goods->cartGoods([
  782. 'id' => $goods_id,
  783. 'msid' => $msid,
  784. 'tuanid' => $tuanid,
  785. 'sku' => $sku,
  786. 'quantity' => $number,
  787. 'is_skumore' => $is_skumore,
  788. 'skumore' => $skumore
  789. ]);
  790. $data["amountTotle"] = $buygoods['total'];
  791. $data["totalPayPoints"] = $buygoods['totalPayPoints'];
  792. $data['totalPointsPrice'] = $buygoods['totalPointsPrice'];
  793. $data['is_additional'] = $buygoods['is_additional'];
  794. if (empty($buygoods['weight'])) {
  795. $buygoods['weight'] = 0.1;
  796. }
  797. $weight = $buygoods['weight'];
  798. //var_dump($weight);
  799. } else {
  800. $cart = new Cart;
  801. $cartgoods = $cart->getlistbyid($cartid);
  802. $data["amountTotle"] = $cartgoods['totalprice'];
  803. $data["totalPayPoints"] = $cartgoods['totalPayPoints'];
  804. $data['totalPointsPrice'] = $cartgoods['totalPointsPrice'];
  805. $data['is_additional'] = $cartgoods['is_additional'];
  806. $weight = $cartgoods['weight'];
  807. }
  808. $data["thefare"] = 0;
  809. //收货人
  810. if (!empty($address_id)) {
  811. $shipping = Address::find($address_id);
  812. if (!empty($shipping)) {
  813. $shipping = $shipping->toArray();
  814. }
  815. if ($ptype == 1) {
  816. $shipping_city_id = Area::get_area_id($shipping['city_name']);
  817. $Transport = (new TransportExtend)->calc_transport($weight, $shipping_city_id);
  818. $amountLogistics = $Transport['price'];
  819. }
  820. if ($technicalId && $ptype == 2) {
  821. $thefare = Address::getthefare($address_id, $technicalId);
  822. $data["distance"] = $thefare['distance'];
  823. $data["thefare"] = $thefare['thefare'];
  824. }
  825. }
  826. $Membermob = new Member;
  827. $Member = $Membermob->getUserByWechat();
  828. //订阅消息模板
  829. $tmplIds = Config::getconfig('subscribemessage');
  830. $data['tmplIds'][] = $tmplIds['pay_tpl'];
  831. $data['tmplIds'][] = $tmplIds['staff_tpl'];
  832. if ($data['is_additional'] == 1) {
  833. $data['tmplIds'][] = $tmplIds['itional_tpl'];
  834. } else {
  835. $data['tmplIds'][] = $tmplIds['complete_tpl'];
  836. }
  837. $data["memberPoints"] = $Member['points'];
  838. $test['shipping_method'] = '快递';
  839. $test['weight'] = $weight;
  840. $test['shipping_city_id'] = $shipping_city_id;
  841. $data["amountLogistics"] = (float) $amountLogistics;
  842. $data['charge'] = $charge;
  843. $data["isNeedLogistics"] = 1;
  844. $data['test'] = $test;
  845. $data["amountTotle"] = round($data["amountTotle"], 2);
  846. return $this->json(['data' => $data]);
  847. }
  848. //直接使用余额支付
  849. public function pay()
  850. {
  851. $orderid = input('post.orderid', '', 'serach_in');
  852. //付款前检查库存
  853. $result = Order::getGoodsquantitiy($orderid);
  854. if ($result) {
  855. $orderinfo = Order::find($orderid);
  856. if (!empty($orderinfo)) {
  857. $orderinfo = $orderinfo->toArray();
  858. $money = $orderinfo['total'];
  859. $Member = Member::find(UID());
  860. if (!empty($Member) && ($Member->balance >= $money)) {
  861. Member::where('id', UID())
  862. ->dec('balance', $money)
  863. ->update();
  864. Order::update(['id' => $orderid, 'pay_time' => time(), 'payment_code' => 'balance_pay']);
  865. $ordermod = new Order;
  866. $ordermod->pay_order(['order_num_alias' => $orderinfo['order_num_alias'], 'nosendmessage' => 1]);
  867. } else {
  868. $errno = 1;
  869. $message = '余额不足';
  870. }
  871. } else {
  872. $errno = 1;
  873. $message = '订单不存在';
  874. }
  875. } else {
  876. $errno = 2;
  877. $message = '库存量不足';
  878. }
  879. return $this->json(['msg' => $message, 'message' => $message, 'errno' => $errno, 'data' => $data]);
  880. }
  881. public function delivery()
  882. {
  883. $orderid = input('post.orderid', '', 'serach_in');
  884. $orderinfo = Order::find($orderid);
  885. if (!empty($orderinfo)) {
  886. Order::settlement($orderid);
  887. } else {
  888. $errno = 1;
  889. $message = '订单不存在';
  890. }
  891. return $this->json(['message' => $message, 'errno' => $errno, 'data' => $data]);
  892. }
  893. //2023-3-9已移到PaymethodController的list
  894. //支付方式列表
  895. public function paymethod()
  896. {
  897. $data = Paymethod::where(['weid' => weid(), 'status' => 1])
  898. ->order('sort asc')
  899. ->select()
  900. ->toArray();
  901. $data[0]['default'] = $data[0]['default']['code'];
  902. foreach ($data as $i => $vo) {
  903. if (empty($vo['code'])) {
  904. unset($data[$i]);
  905. }
  906. if (($vo['code'] == 'wx_pay')) {
  907. $data[0]['default'] = $vo['code'];
  908. }
  909. }
  910. if (empty($data)) {
  911. Paymethod::update(['code' => 'wx_pay', 'weid' => 0]);
  912. $data = Paymethod::where(['weid' => 0])->order('sort asc')->select()->toArray();
  913. }
  914. if (empty($data[0]['default'])) {
  915. $data[0]['default'] = $data[0]['code'];
  916. }
  917. return $this->json(['data' => $data]);
  918. }
  919. }