OrderController.php 39 KB

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