Buy.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. <?php
  2. # 支付
  3. namespace Mshop\Lib;
  4. use Dever;
  5. class Buy
  6. {
  7. # 1是用户自己看,2是门店看
  8. public $type = 1;
  9. # 1是列表,2是详情
  10. public $view = 1;
  11. # 获取配置
  12. public $config = array();
  13. # table
  14. public $table = 'shop/buy_order';
  15. public function __construct()
  16. {
  17. $this->config = Dever::db($this->table)->config;
  18. }
  19. # 设置订单的类型
  20. public function set($type, $view)
  21. {
  22. $this->type = $type;
  23. $this->view = $view;
  24. return $this;
  25. }
  26. # 获取公共的where
  27. public function where($id)
  28. {
  29. $where = array();
  30. $where['shop_id'] = $id;
  31. if (!$where) {
  32. Dever::alert('参数错误');
  33. }
  34. return $where;
  35. }
  36. # 获取订单列表
  37. public function getList($id)
  38. {
  39. $result = array();
  40. $where = $this->where($id);
  41. $mobile = Dever::input('mobile');
  42. if ($mobile) {
  43. $where['mobile'] = $mobile;
  44. }
  45. $status = Dever::input('status');
  46. if ($status) {
  47. $where['status'] = $status;
  48. }
  49. $result['search_value'] = $where;
  50. $result['search_value']['day'] = $day = Dever::input('day');
  51. if ($day) {
  52. $where['start'] = Dever::maketime($day . ' 00:00:00');
  53. $where['end'] = Dever::maketime($day . ' 23:59:59');
  54. }
  55. $result['order'] = Dever::db($this->table)->getAll($where);
  56. if ($result['order']) {
  57. foreach ($result['order'] as $k => $v) {
  58. $result['order'][$k] = $this->getInfo($v);
  59. }
  60. }
  61. $result['search'] = array();
  62. $result['search']['status'] = array
  63. (
  64. array('value' => 1, 'name' => '待支付'),
  65. array('value' => 2, 'name' => '待审核'),
  66. array('value' => 3, 'name' => '待发货'),
  67. array('value' => 4, 'name' => '待收货确认'),
  68. array('value' => 5, 'name' => '已完成'),
  69. array('value' => 6, 'name' => '已完成(有退款)'),
  70. array('value' => '7,8,11', 'name' => '已取消'),
  71. );
  72. return $result;
  73. }
  74. # 查看详情
  75. public function getView($id, $order_id, $show = true)
  76. {
  77. $where = $this->where($id);
  78. $where['id'] = $order_id;
  79. $result = Dever::db($this->table)->find($where);
  80. if (!$result) {
  81. Dever::alert('订单不存在');
  82. }
  83. if ($show) {
  84. $result = $this->getInfo($result, true);
  85. }
  86. return $result;
  87. }
  88. # 查看退款详情
  89. public function getRefund($id, $order_id)
  90. {
  91. $data = $this->getView($id, $order_id, false);
  92. $data['refund'] = Dever::db('shop/buy_order_refund')->select(array('order_id' => $info['id']));
  93. return $data;
  94. }
  95. # 获取订单详细信息
  96. public function getInfo($info, $view = false)
  97. {
  98. if ($info['status'] == 1) {
  99. # 15分钟内支付,900秒
  100. $m = 9000;
  101. # 支付倒计时
  102. $info['time'] = time() - $info['cdate'];
  103. if ($info['time'] >= $m) {
  104. # 已过期,自动取消
  105. $info['time'] = -1;
  106. Dever::db($this->table)->update(array('where_id' => $info['id'], 'status' => 11));
  107. $info['status'] = 11;
  108. } else {
  109. $info['time'] = $m - $info['time'];
  110. }
  111. }
  112. $info['status_name'] = $this->config['status'][$info['status']];
  113. $info['goods'] = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
  114. $info['shop'] = Dever::db('shop/info')->getOne($info['shop_id']);
  115. $info['cdate'] = date('Y-m-d H:i', $info['cdate']);
  116. $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
  117. $goods_process = Dever::db('shop/buy_order_refund')->config['process'];
  118. if ($view) {
  119. foreach ($info['goods'] as $k => $v) {
  120. $info['goods'][$k]['info'] = Dever::load('goods/lib/info')->getPayInfo($v['goods_id'], $v['sku_id']);
  121. $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
  122. }
  123. } else {
  124. foreach ($info['goods'] as $k => $v) {
  125. $goods = Dever::db('goods/info')->one($v['goods_id']);
  126. $info['goods'][$k]['name'] = $goods['name'];
  127. $info['goods'][$k]['cover'] = $goods['cover'];
  128. $info['goods'][$k]['status_name'] = $goods_status[$v['status']];
  129. }
  130. }
  131. if (!$info['refund_cash']) {
  132. $info['refund_cash'] = 0;
  133. }
  134. if ($info['fdate']) {
  135. $info['fdate'] = date('Y-m-d H:i', $info['fdate']);
  136. }
  137. if ($info['qfdate']) {
  138. $info['qfdate'] = date('Y-m-d H:i', $info['qfdate']);
  139. }
  140. if ($info['operdate']) {
  141. $info['operdate'] = date('Y-m-d H:i', $info['operdate']);
  142. }
  143. if ($info['shdate']) {
  144. $info['shdate'] = date('Y-m-d H:i', $info['shdate']);
  145. }
  146. return $info;
  147. }
  148. # 发起支付
  149. public function action($shop, $name, $num, $goods, $price, $info, $refer = '')
  150. {
  151. if (!$shop) {
  152. Dever::alert('错误的门店信息');
  153. }
  154. $order_data['shop_id'] = $shop['id'];
  155. $order_data['mobile'] = $shop['mobile'];
  156. $order_data['name'] = $name;
  157. $order_data['num'] = $num;
  158. $order_data['info'] = $info;
  159. $order_data['price'] = $price;
  160. $order_data['area'] = $shop['area'];
  161. $order_data['province'] = $shop['province'];
  162. $order_data['city'] = $shop['city'];
  163. $order_data['county'] = $shop['county'];
  164. $order_data['town'] = $shop['town'];
  165. $order_data['order_num'] = $this->getOrderId();
  166. $id = Dever::db('shop/buy_order')->insert($order_data);
  167. if (!$id) {
  168. Dever::alert('支付失败');
  169. }
  170. foreach($goods as $k => $v) {
  171. $data['shop_id'] = $shop['id'];
  172. $data['order_id'] = $id;
  173. $data['goods_id'] = $v['id'];
  174. $data['sku_id'] = $v['sku_id'];
  175. $data['price'] = $v['price'] * $v['buy_num'];
  176. $data['num'] = $v['buy_num'];
  177. Dever::db('shop/buy_order_goods')->insert($data);
  178. }
  179. if ($price <= 0) {
  180. $param['pay_product_id'] = $id;
  181. $param['pay_order_id'] = $order_data['order_num'];
  182. $param['pay_status'] = 2;
  183. $param['pay_cash'] = $price;
  184. $param['pay_msg'] = '';
  185. $this->success($param);
  186. return array
  187. (
  188. 'order' => '',
  189. 'order_num' => $order_data['order_num'],
  190. 'order_id' => $id,
  191. 'type' => 'pay',
  192. );
  193. }
  194. $param = array
  195. (
  196. 'project_id' => 2,
  197. 'channel_id' => 1,
  198. 'system_source' => 5,
  199. 'uid' => -1,
  200. 'name' => $order_data['name'],
  201. 'cash' => $price,
  202. 'product_id' => $id,
  203. 'order_id' => $order_data['order_num'],
  204. 'refer' => $refer,
  205. );
  206. $receipt = Dever::input('receipt');
  207. if ($receipt) {
  208. $param['receipt'] = $receipt;
  209. }
  210. //$result = Dever::load('pay/api.pay', $param);
  211. $result['type'] = 'test';
  212. $result['order'] = '';
  213. $result['order_num'] = $order_data['order_num'];
  214. $result['order_id'] = $id;
  215. return $result;
  216. }
  217. # 再次发起支付
  218. public function raction($id, $refer = '')
  219. {
  220. $order = Dever::db('shop/buy_order')->find($id);
  221. if (!$order) {
  222. Dever::alert('订单信息错误');
  223. }
  224. if ($order['status'] > 1) {
  225. Dever::alert('订单已支付或已取消');
  226. }
  227. $param = array
  228. (
  229. 'project_id' => 2,
  230. 'channel_id' => 1,
  231. 'system_source' => 5,
  232. 'uid' => -1,
  233. 'name' => $order['name'],
  234. 'cash' => $order['price'],
  235. 'product_id' => $id,
  236. 'order_id' => $order['order_num'],
  237. 'refer' => $refer,
  238. );
  239. $receipt = Dever::input('receipt');
  240. if ($receipt) {
  241. $param['receipt'] = $receipt;
  242. }
  243. $result = Dever::load('pay/api.pay', $param);
  244. $result['order_num'] = $order['order_num'];
  245. $result['order_id'] = $id;
  246. return $result;
  247. }
  248. # 支付成功回调 安全加密 设置token
  249. public function success_secure_api_token()
  250. {
  251. $project_id = Dever::input('pay_project_id');
  252. $info = Dever::db('pay/project')->one($project_id);
  253. if ($info) {
  254. return $info['key'];
  255. }
  256. return 'shop_buy_dever_2020';
  257. }
  258. # 支付成功回调 安全加密
  259. public function success_secure_api($param = array())
  260. {
  261. $this->success($param);
  262. }
  263. # 支付成功回调
  264. public function success($param = array())
  265. {
  266. $send = $param ? $param : Dever::preInput('pay_');
  267. $product_id = $send['pay_product_id'];
  268. $order_id = $send['pay_order_id'];
  269. $status = $send['pay_status'];
  270. $cash = $send['pay_cash'];
  271. $msg = $send['pay_msg'];
  272. $order = Dever::db('shop/buy_order')->one(array('id' => $product_id, 'time' => time()));
  273. if ($order && $order['status'] == 1) {
  274. if ($status == 2) {
  275. }
  276. $update['status'] = 2;
  277. $update['where_id'] = $order['id'];
  278. Dever::db('shop/buy_order')->update($update);
  279. }
  280. return 'ok';
  281. }
  282. # 生成订单号
  283. public function getOrderId()
  284. {
  285. $where['order_num'] = Dever::order('C');
  286. $state = Dever::db('shop/buy_order')->one($where);
  287. if (!$state) {
  288. return $where['order_num'];
  289. } else {
  290. return $this->getOrderId();
  291. }
  292. }
  293. # 确认收货
  294. public function finish($id, $order_id)
  295. {
  296. $data = $this->getView($id, $order_id, false);
  297. if ($data['status'] <= 4) {
  298. if ($data['refund_cash'] > 0) {
  299. $status = 6;
  300. } else {
  301. $status = 5;
  302. }
  303. $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => $status, 'qsdate' => time()));
  304. if ($state) {
  305. # 增加库存
  306. $where['order_id'] = $data['id'];
  307. $where['status'] = 1;
  308. $data = Dever::db('shop/buy_order_goods')->select($where);
  309. if ($data) {
  310. Dever::load('shop/lib/goods')->oper(1, 1, $data);
  311. }
  312. }
  313. return 'ok';
  314. } else {
  315. Dever::alert('您没有权限');
  316. }
  317. }
  318. # 取消订单
  319. public function cancel($id, $order_id)
  320. {
  321. $data = $this->getView($id, $order_id, false);
  322. if ($data['status'] == 1) {
  323. $state = Dever::db('shop/buy_order')->update(array('where_id' => $data['id'], 'status' => 7, 'operdate' => time()));
  324. return 'ok';
  325. } else {
  326. Dever::alert('当前订单状态不允许取消');
  327. }
  328. }
  329. # 发货
  330. public function send_api()
  331. {
  332. $id = Dever::input('id');
  333. $process = Dever::input('process', 3);
  334. $info = Dever::db('shop/buy_order_refund')->find($id);
  335. if ($info && $info['process'] == 1) {
  336. $update['process'] = $process;
  337. $update['where_id'] = $info['id'];
  338. $state = Dever::db('shop/buy_order_refund')->update($update);
  339. if ($state && $process == 2) {
  340. $data = $this->getView($info['shop_id'], $info['order_id'], false);
  341. if ($data) {
  342. if ($info['order_goods_id'] > 0) {
  343. $state = Dever::db('shop/buy_order_goods')->update(array('where_id' => $info['order_goods_id'], 'status' => 3));
  344. $this->pay_refund($state, $data, $info['cash']);
  345. # 检查这个订单下的商品是不是都退了
  346. $total = Dever::db('shop/buy_order_goods')->total(array('order_id' => $info['order_id'], 'shop_id' => $id, 'status' => 1));
  347. if ($total <= 0) {
  348. $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
  349. }
  350. } else {
  351. # 全部退款
  352. $state = Dever::db('shop/buy_order')->update(array('where_id' => $info['order_id'], 'status' => 8));
  353. $this->pay_refund($state, $data, $info['cash']);
  354. }
  355. }
  356. }
  357. }
  358. return 'ok';
  359. }
  360. # 查看订单状态
  361. public function orderStatus($id)
  362. {
  363. $config = Dever::db('shop/buy_order')->config;
  364. $info = Dever::db('shop/buy_order')->one($id);
  365. $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'process' => 1));
  366. $status = $config['status'][$info['status']];
  367. if ($tk) {
  368. $status = '申请退款中';
  369. }
  370. return $status;
  371. }
  372. # 后台审核退款
  373. public function refund_api()
  374. {
  375. $id = Dever::input('id');
  376. $process = Dever::input('process');
  377. return Dever::load('shop/lib/refund')->set('buy')->action($id, $process, false);
  378. }
  379. # 展示订单详情
  380. public function show()
  381. {
  382. $id = Dever::input('order_id');
  383. $config = Dever::db('shop/buy_order')->config;
  384. $info = Dever::db('shop/buy_order')->one($id);
  385. $shop = Dever::db('shop/info')->find($info['shop_id']);
  386. $tk_status = Dever::db('shop/buy_order_refund')->config['status'];
  387. $tk_process = Dever::db('shop/buy_order_refund')->config['process'];
  388. $status = $config['status'][$info['status']];
  389. $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'type' => 1));
  390. $html = '[基本信息]:<table class="layui-table"><thead><tr><th style="width:20%">项目</th><th style="width:80%">详情</th></tr> </thead><tbody>';
  391. $html .= '<tr>
  392. <td>订单号</td>
  393. <td>'.$this->table(false, array(array($info['order_num']))).'</td>
  394. </tr>';
  395. $html .= '<tr>
  396. <td>门店信息</td>
  397. <td>'.$this->table(false, array(array('门店名称:' . $shop['name'], '联系人:' . $shop['truename'], '联系电话:' . $shop['mobile']))).'</td>
  398. </tr>';
  399. $url = Dever::url('lib/buy.refund', 'mshop');
  400. if ($tk && $tk['process'] == 1) {
  401. $status = '申请' . $tk_status[$tk['status']];
  402. $process = $tk_process[$tk['process']];
  403. $process = '';
  404. if ($tk['process'] == 1) {
  405. $process .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
  406. }
  407. $html .= '<tr>
  408. <td>订单信息</td>
  409. <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态', '审核状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status, $process))).'</td>
  410. </tr>';
  411. } else {
  412. $html .= '<tr>
  413. <td>订单信息</td>
  414. <td>'.$this->table(array('金额', '退款金额', '数量', '订单状态'), array(array($info['price'], $info['refund_cash'], $info['num'], $status))).'</td>
  415. </tr>';
  416. }
  417. # 增加仓库和工厂信息
  418. $html .= '</tbody></table>';
  419. $html .= '[商品清单]:';
  420. $head = array('名称', '属性', '价格', '数量', '状态');
  421. $body = array();
  422. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $info['id']));
  423. $goods_status = Dever::db('shop/buy_order_goods')->config['status'];
  424. foreach ($goods as $k => $v) {
  425. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  426. $status = $goods_status[$v['status']];
  427. $tk = Dever::db('shop/buy_order_refund')->find(array('order_id' => $info['id'], 'order_goods_id' => $v['id'], 'type' => 2));
  428. if ($tk && $tk['process'] == 1) {
  429. $status = '申请' . $tk_status[$tk['status']];
  430. //$status .= '&nbsp;&nbsp;[' . $tk_process[$tk['process']] . ']';
  431. if ($tk['process'] == 1) {
  432. $status .= '&nbsp;&nbsp;<a href="javascript:;" onclick="audit('.$tk['id'].', 2, \''.$url.'\')" class="layui-btn">通过</a><a href="javascript:;" onclick="audit('.$tk['id'].', 3, \''.$url.'\')" class="layui-btn layui-btn-danger">驳回</a>';
  433. }
  434. }
  435. $body[$k] = array
  436. (
  437. $goods_info['name'],
  438. $v['price'],
  439. $v['price'],
  440. $v['num'],
  441. $status,
  442. );
  443. }
  444. $html .= $this->table($head, $body);
  445. return $html;
  446. }
  447. private function table($head, $data)
  448. {
  449. $html = '';
  450. if ($head) {
  451. $html = '<table class="layui-table">';
  452. $html .= '<thead><tr>';
  453. foreach ($head as $k => $v) {
  454. $html .= '<th>'.$v.'</th>';
  455. }
  456. $html .= '</tr></thead>';
  457. $html .= '<tbody>';
  458. foreach ($data as $k => $v) {
  459. $html .= '<tr>';
  460. foreach ($v as $k1 => $v1) {
  461. $html .= '<td>'.$v1.'</td>';
  462. }
  463. $html .= '</tr>';
  464. }
  465. $html .= '</tbody>';
  466. $html .= '</table>';
  467. } else {
  468. foreach ($data as $k => $v) {
  469. $html .= '';
  470. foreach ($v as $k1 => $v1) {
  471. $html .= $v1 . '&nbsp;&nbsp;&nbsp;&nbsp;';
  472. }
  473. $html .= '';
  474. }
  475. }
  476. return $html;
  477. }
  478. # 采购订单审核 拆单
  479. public function audit()
  480. {
  481. $order_id = Dever::input('order_id');
  482. $info = Dever::db('shop/buy_order')->find($order_id);
  483. if (!$info || ($info && $info['status'] != 2)) {
  484. Dever::alert('当前订单状态无法拆单');
  485. }
  486. $goods = Dever::db('shop/buy_order_goods')->select(array('order_id' => $order_id));
  487. $shop = Dever::db('shop/info')->find($info['shop_id']);
  488. # 获取门店分配的仓库和工厂
  489. $shop_store = Dever::db('shop/store')->select(array('shop_id' => $shop['id']));
  490. $store = array();
  491. $distance = array();
  492. # 按照距离排序
  493. foreach ($shop_store as $k => $v) {
  494. $info = Dever::db('store/info')->find($v['store_id']);
  495. if ($info && $info['status'] == 1) {
  496. $distance[] = $info['distance'] = Dever::distance($shop['lng'], $shop['lat'], $info['lng'], $info['lat']);
  497. $store[] = $info;
  498. }
  499. }
  500. array_multisort($distance, SORT_ASC, SORT_NUMERIC, $store);
  501. $shop_factory = Dever::db('shop/factory')->select(array('shop_id' => $shop['id']));
  502. $factory = array();
  503. $distance = array();
  504. # 按照距离排序
  505. foreach ($shop_factory as $k => $v) {
  506. $info = Dever::db('factory/info')->find($v['factory_id']);
  507. if ($info && $info['status'] == 1) {
  508. $distance[] = $info['distance'] = Dever::distance($shop['lng'], $shop['lat'], $info['lng'], $info['lat']);
  509. $factory[] = $info;
  510. }
  511. }
  512. array_multisort($distance, SORT_ASC, SORT_NUMERIC, $factory);
  513. print_r($store);
  514. print_r($factory);die;
  515. $num = 0;
  516. foreach ($goods as $k => $v) {
  517. # 开始找仓库
  518. $find = $this->store($order_id, $shop, $store, $v);
  519. if (!$find[1]) {
  520. # 仓库没有,找厂家
  521. if ($factory) {
  522. $find = $this->factory($order_id, $shop, $factory, $v);
  523. }
  524. if (!$find[1]) {
  525. # 啥都没找到怎么办?
  526. }
  527. }
  528. if ($find[1]) {
  529. $num++;
  530. Dever::db('shop/buy_order_goods')->update(array('where_id' => $v['id'], 'status' => 2, 'type' => $find[0], 'type_id' => implode(',', $find[1])));
  531. }
  532. }
  533. if ($num > 0) {
  534. Dever::db('shop/buy_order')->update(array('where_id' => $info['id'], 'status' => 3));
  535. } else {
  536. Dever::db('shop/buy_order')->update(array('where_id' => $info['id'], 'status' => 7));
  537. }
  538. }
  539. private function store($order_id, $shop, $store, $goods, $state = 2)
  540. {
  541. $find = array();
  542. $id = array();
  543. if (!$store) {
  544. return array(1, $id);
  545. }
  546. foreach ($store as $k => $v) {
  547. $where['store_id'] = $v['id'];
  548. $where['goods_id'] = $goods['goods_id'];
  549. $where['sku_id'] = ($goods['sku_id'] && $goods['sku_id'] > 0) ? $goods['sku_id'] : -1;
  550. $sku = Dever::db('store/goods_sku')->getOne($where);
  551. if ($sku) {
  552. if ($goods['num'] <= $sku['total']) {
  553. # 如果库存符合,直接下单即可,生成仓库订单
  554. $state = Dever::load('store/lib/order')->pay($order_id, $shop['id'], $where['store_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
  555. if ($state) {
  556. $id[] = $where['store_id'];
  557. break;
  558. }
  559. } elseif ($state == 1 && $sku['total'] > 0) {
  560. # 如果库存不够,从这个仓库扣下一部分,剩余的从另外仓库处理
  561. $goods['num'] = $goods['num'] - $sku['total'];
  562. # 生成仓库订单
  563. $state = Dever::load('store/lib/order')->pay($order_id, $shop['id'], $where['store_id'], $goods['price'], $sku['total'], $where['goods_id'], $where['sku_id']);
  564. if (!$state) {
  565. $goods['num'] = $goods['num'] + $sku['total'];
  566. } else {
  567. $id[] = $where['store_id'];
  568. }
  569. continue;
  570. } else {
  571. # 直接切换到下一个仓库处理
  572. continue;
  573. }
  574. }
  575. }
  576. return array(1, $id);
  577. }
  578. private function factory($order_id, $shop, $factory, $goods)
  579. {
  580. $find = array();
  581. $id = array();
  582. if (!$factory) {
  583. return array(1, $id);
  584. }
  585. foreach ($factory as $k => $v) {
  586. $where['factory_id'] = $v['id'];
  587. $where['goods_id'] = $goods['goods_id'];
  588. $where['sku_id'] = ($goods['sku_id'] && $goods['sku_id'] > 0) ? $goods['sku_id'] : -1;
  589. $sku = Dever::db('factory/goods_sku')->getOne($where);
  590. if ($sku) {
  591. $state = Dever::load('factory/lib/order')->pay($order_id, $shop['id'], $where['factory_id'], $goods['price'], $goods['num'], $where['goods_id'], $where['sku_id']);
  592. if ($state) {
  593. $id[] = $where['factory_id'];
  594. break;
  595. }
  596. } else {
  597. continue;
  598. }
  599. }
  600. return array(2, $id);
  601. }
  602. }