Order.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. <?php
  2. namespace app\common\model;
  3. use think\facade\Db;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 数据层模型
  10. */
  11. class Order extends BaseModel
  12. {
  13. public $page_info;
  14. public $lock = false; //是否加锁
  15. /**
  16. * 取单条订单信息
  17. * @access public
  18. * @author csdeshang
  19. * @param array $condition 条件
  20. * @param array $extend 扩展
  21. * @param string $fields 字段
  22. * @param array $order 排序
  23. * @param array $group 分组
  24. * @return array
  25. */
  26. public function getOrderInfo($condition = array(), $extend = array(), $fields = '*', $order = '', $group = '')
  27. {
  28. $order_info = Db::name('order')->field($fields)->where($condition)->lock($this->lock)->group($group)->order($order)->find();
  29. if (empty($order_info)) {
  30. return array();
  31. }
  32. if (isset($order_info['order_state'])) {
  33. $order_info['state_desc'] = get_order_state($order_info);
  34. }
  35. if (isset($order_info['payment_code'])) {
  36. $order_info['payment_name'] = get_order_payment_name($order_info['payment_code']);
  37. }
  38. //追加返回订单扩展表信息
  39. if (in_array('order_common', $extend)) {
  40. $order_info['extend_order_common'] = $this->getOrdercommonInfo(array('order_id' => $order_info['order_id']));
  41. $order_info['extend_order_common']['reciver_info'] = unserialize($order_info['extend_order_common']['reciver_info']);
  42. $order_info['extend_order_common']['invoice_info'] = unserialize($order_info['extend_order_common']['invoice_info']);
  43. }
  44. //追加返回店铺信息
  45. if (in_array('store', $extend)) {
  46. $order_info['extend_store'] = model('store')->getStoreInfo(array('store_id' => $order_info['store_id']));
  47. }
  48. //返回买家信息
  49. if (in_array('member', $extend)) {
  50. $order_info['extend_member'] = model('member')->getMemberInfoByID($order_info['buyer_id']);
  51. }
  52. //追加返回商品信息
  53. if (in_array('order_goods', $extend)) {
  54. //取商品列表
  55. $order_goods_list = $this->getOrdergoodsList(array('order_id' => $order_info['order_id']));
  56. $order_info['extend_order_goods'] = $order_goods_list;
  57. }
  58. //追加返回拼团订单信息
  59. if (in_array('ppintuanorder', $extend)) {
  60. //取拼团订单附加列表
  61. $pintuanorder_list = model('ppintuanorder')->getPpintuanorderList(array('ppintuanorder.order_id' => $order_info['order_id'], 'pintuanorder_type' => 0));
  62. if (!empty($pintuanorder_list)) {
  63. foreach ($pintuanorder_list as $value) {
  64. $order_info['pintuan_id'] = $value['pintuan_id'];
  65. $order_info['pintuangroup_id'] = $value['pintuangroup_id'];
  66. $order_info['pintuanorder_state'] = $value['pintuanorder_state'];
  67. $order_info['pintuanorder_state_text'] = $value['pintuanorder_state_text'];
  68. }
  69. }
  70. }
  71. return $order_info;
  72. }
  73. /**
  74. * 获取订单信息
  75. * @access public
  76. * @author csdeshang
  77. * @param array $condition 条件
  78. * @param string $field 字段
  79. * @return array
  80. */
  81. public function getOrdercommonInfo($condition = array(), $field = '*')
  82. {
  83. return Db::name('ordercommon')->where($condition)->find();
  84. }
  85. /**
  86. * 获取订单信息
  87. * @access public
  88. * @author csdeshang
  89. * @param array $condition 条件
  90. * @return type
  91. */
  92. public function getOrderpayInfo($condition = array())
  93. {
  94. return Db::name('orderpay')->where($condition)->find();
  95. }
  96. /**
  97. * 取得支付单列表
  98. * @access public
  99. * @author csdeshang
  100. * @param array $condition 条件
  101. * @param string $field 字段
  102. * @param string $order 排序
  103. * @param string $key 以哪个字段作为下标,这里一般指pay_id
  104. * @return array
  105. */
  106. public function getOrderpayList($condition, $field = '*', $order = '', $key = '')
  107. {
  108. $pay_list = Db::name('orderpay')->field($field)->where($condition)->order($order)->select()->toArray();
  109. if ($key) {
  110. $pay_list = ds_change_arraykey($pay_list, $key);
  111. }
  112. return $pay_list;
  113. }
  114. /**
  115. * 取得订单列表(未被删除)
  116. * @access public
  117. * @author csdeshang
  118. * @param unknown $condition 条件
  119. * @param string $pagesize 分页
  120. * @param string $field 字段
  121. * @param string $order 排序
  122. * @param string $limit 限制
  123. * @param unknown $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
  124. * @return Ambigous <multitype:boolean Ambigous <string, mixed> , unknown>
  125. */
  126. public function getNormalOrderList($condition, $pagesize = '', $field = '*', $order = 'order_id desc', $limit = 0, $extend = array())
  127. {
  128. $condition[] = array('delete_state', '=', 0);
  129. return $this->getOrderList($condition, $pagesize, $field, $order, $limit, $extend);
  130. }
  131. /**
  132. * 取得订单列表(所有)
  133. * @access public
  134. * @author csdeshang
  135. * @param unknown $condition 条件
  136. * @param string $pagesize 分页
  137. * @param string $field 字段
  138. * @param string $order 排序
  139. * @param string $limit 限制
  140. * @param unknown $extend 追加返回那些表的信息,如array('order_common','order_goods','store')
  141. * @return Ambigous <multitype:boolean Ambigous <string, mixed> , unknown>
  142. */
  143. public function getOrderList($condition, $pagesize = '', $field = '*', $order = 'order_id desc', $limit = 0, $extend = array())
  144. {
  145. if ($pagesize) {
  146. $list_paginate = Db::name('order')->field($field)->where($condition)->order($order)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  147. $this->page_info = $list_paginate;
  148. $list = $list_paginate->items();
  149. } else {
  150. $list = Db::name('order')->field($field)->where($condition)->order($order)->limit($limit)->select()->toArray();
  151. }
  152. if (empty($list))
  153. return array();
  154. $order_list = array();
  155. foreach ($list as $order) {
  156. if (isset($order['order_state'])) {
  157. $order['state_desc'] = get_order_state($order);
  158. }
  159. if (isset($order['payment_code'])) {
  160. $order['payment_name'] = get_order_payment_name($order['payment_code']);
  161. }
  162. if (!empty($extend))
  163. $order_list[$order['order_id']] = $order;
  164. }
  165. if (empty($order_list))
  166. $order_list = $list;
  167. //追加返回订单扩展表信息
  168. if (in_array('order_common', $extend)) {
  169. $order_common_list = $this->getOrdercommonList(array(array('order_id', 'in', array_keys($order_list))));
  170. foreach ($order_common_list as $value) {
  171. $order_list[$value['order_id']]['extend_order_common'] = $value;
  172. $order_list[$value['order_id']]['extend_order_common']['reciver_info'] = @unserialize($value['reciver_info']);
  173. $order_list[$value['order_id']]['extend_order_common']['invoice_info'] = @unserialize($value['invoice_info']);
  174. }
  175. }
  176. //追加返回店铺信息
  177. if (in_array('store', $extend)) {
  178. $store_id_array = array();
  179. foreach ($order_list as $value) {
  180. if (!in_array($value['store_id'], $store_id_array))
  181. $store_id_array[] = $value['store_id'];
  182. }
  183. $store_list = Db::name('store')->where('store_id', 'in', array_values($store_id_array))->select()->toArray();
  184. $store_new_list = array();
  185. foreach ($store_list as $store) {
  186. $store_new_list[$store['store_id']] = $store;
  187. }
  188. foreach ($order_list as $order_id => $order) {
  189. $order_list[$order_id]['extend_store'] = isset($store_new_list[$order['store_id']]) ? $store_new_list[$order['store_id']] : '';
  190. }
  191. }
  192. //追加返回买家信息
  193. if (in_array('member', $extend)) {
  194. foreach ($order_list as $order_id => $order) {
  195. $order_list[$order_id]['extend_member'] = model('member')->getMemberInfoByID($order['buyer_id']);
  196. }
  197. }
  198. //追加返回商品信息
  199. if (in_array('order_goods', $extend)) {
  200. //取商品列表
  201. $order_goods_list = Db::name('ordergoods')->where('order_id', 'in', array_keys($order_list))->select()->toArray();
  202. if (!empty($order_goods_list)) {
  203. foreach ($order_goods_list as $value) {
  204. $order_list[$value['order_id']]['extend_order_goods'][] = $value;
  205. }
  206. } else {
  207. $order_list[$value['order_id']]['extend_order_goods'] = array();
  208. }
  209. }
  210. //追加返回拼团订单信息
  211. if (in_array('ppintuanorder', $extend)) {
  212. //取拼团订单附加列表
  213. $condition = array();
  214. $condition[] = array('ppintuanorder.order_id', 'in', array_keys($order_list));
  215. $condition[] = array('pintuanorder_type', '=', 0);
  216. $pintuanorder_list = model('ppintuanorder')->getPpintuanorderList($condition);
  217. if (!empty($pintuanorder_list)) {
  218. foreach ($pintuanorder_list as $value) {
  219. $order_list[$value['order_id']]['pintuan_id'] = $value['pintuan_id'];
  220. $order_list[$value['order_id']]['pintuangroup_id'] = $value['pintuangroup_id'];
  221. $order_list[$value['order_id']]['pintuanorder_state'] = $value['pintuanorder_state'];
  222. $order_list[$value['order_id']]['pintuanorder_state_text'] = $value['pintuanorder_state_text'];
  223. }
  224. }
  225. }
  226. return $order_list;
  227. }
  228. /**
  229. * 取得(买/卖家)订单某个数量缓存
  230. * @access public
  231. * @author csdeshang
  232. * @param string $type 买/卖家标志,允许传入 buyer、store
  233. * @param int $id 买家ID、店铺ID
  234. * @param string $key 允许传入 NewCount、PayCount、SendCount、EvalCount、TradeCount,分别取相应数量缓存,只许传入一个
  235. * @return array
  236. */
  237. public function getOrderCountCache($type, $id, $key)
  238. {
  239. if (!config('ds_config.cache_open')) return;
  240. $types = $id . '_ordercount' . '_' . $type . '_' . $key;
  241. $count = rcache($types);
  242. return $count;
  243. }
  244. /**
  245. * 设置(买/卖家)订单某个数量缓存
  246. * @access public
  247. * @author csdeshang
  248. * @param string $type 买/卖家标志,允许传入 buyer、store
  249. * @param int $id 买家ID、店铺ID
  250. * @param int $key 允许传入 NewCount、PayCount、SendCount、EvalCount、TradeCount,分别取相应数量缓存,只许传入一个
  251. * @param array $count 数据
  252. * @return type
  253. */
  254. public function editOrderCountCache($type, $id, $key, $count)
  255. {
  256. if (!config('ds_config.cache_open') || empty($type) || !intval($id))
  257. return;
  258. $types = $id . '_ordercount' . '_' . $type . '_' . $key;
  259. wkcache($types, $count);
  260. }
  261. /**
  262. * 取得买卖家订单数量某个缓存
  263. * @access public
  264. * @author csdeshang
  265. * @param string $type $type 买/卖家标志,允许传入 buyer、store
  266. * @param int $id 买家ID、店铺ID
  267. * @param string $key 允许传入 NewCount、PayCount、SendCount、EvalCount、TradeCount,分别取相应数量缓存,只许传入一个
  268. * @return int
  269. */
  270. public function getOrderCountByID($type, $id, $key)
  271. {
  272. $cache_info = $this->getOrderCountCache($type, $id, $key);
  273. if (config('ds_config.cache_open') && is_numeric($cache_info)) {
  274. //从缓存中取得
  275. $count = $cache_info;
  276. } else {
  277. //从数据库中取得
  278. $field = $type == 'buyer' ? 'buyer_id' : 'store_id';
  279. $condition = array();
  280. $condition[] = array($field, '=', $id);
  281. $func = 'getOrderState' . $key;
  282. $count = $this->$func($condition);
  283. $this->editOrderCountCache($type, $id, $key, $count);
  284. }
  285. return $count;
  286. }
  287. /**
  288. * 删除(买/卖家)订单全部数量缓存
  289. * @access public
  290. * @author csdeshang
  291. * @param string $type 买/卖家标志,允许传入 buyer、store
  292. * @param int $id 买家ID、店铺ID
  293. * @return bool
  294. */
  295. public function delOrderCountCache($type, $id)
  296. {
  297. $type_NewCount = $id . '_ordercount' . '_' . $type . '_NewCount';
  298. $type_PayCount = $id . '_ordercount' . '_' . $type . '_PayCount';
  299. $type_SendCount = $id . '_ordercount' . '_' . $type . '_SendCount';
  300. $type_EvalCount = $id . '_ordercount' . '_' . $type . '_EvalCount';
  301. $type_TradeCount = $id . '_ordercount' . '_' . $type . '_TradeCount';
  302. dcache($type_NewCount);
  303. dcache($type_PayCount);
  304. dcache($type_SendCount);
  305. dcache($type_EvalCount);
  306. dcache($type_TradeCount);
  307. }
  308. /**
  309. * 待付款订单数量
  310. * @access public
  311. * @author csdeshang
  312. * @param array $condition 条件
  313. * @return int
  314. */
  315. public function getOrderStateNewCount($condition = array())
  316. {
  317. $condition[] = array('order_state', '=', ORDER_STATE_NEW);
  318. return $this->getOrderCount($condition);
  319. }
  320. /**
  321. * 待发货订单数量
  322. * @access public
  323. * @author csdeshang
  324. * @param array $condition 条件
  325. * @return int
  326. */
  327. public function getOrderStatePayCount($condition = array())
  328. {
  329. $condition[] = array('order_state', '=', ORDER_STATE_PAY);
  330. return $this->getOrderCount($condition);
  331. }
  332. /**
  333. * 待收货订单数量
  334. * @access public
  335. * @author csdeshang
  336. * @param array $condition 条件
  337. * @return int
  338. */
  339. public function getOrderStateSendCount($condition = array())
  340. {
  341. $condition[] = array('order_state', '=', ORDER_STATE_SEND);
  342. return $this->getOrderCount($condition);
  343. }
  344. /**
  345. * 待评价订单数量
  346. * @access public
  347. * @author csdeshang
  348. * @param type $condition 检索条件
  349. * @return type
  350. */
  351. public function getOrderStateEvalCount($condition = array())
  352. {
  353. $condition[] = array('order_state', '=', ORDER_STATE_SUCCESS);
  354. $condition[] = array('evaluation_state', '=', 0);
  355. $condition[] = array('refund_state', '=', 0);
  356. return $this->getOrderCount($condition);
  357. }
  358. /**
  359. * 交易中的订单数量
  360. * @access public
  361. * @author csdeshang
  362. * @param array $condition 条件
  363. * @return int
  364. */
  365. public function getOrderStateTradeCount($condition = array())
  366. {
  367. $condition[] = array('order_state', 'not in', array(ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS));
  368. return $this->getOrderCount($condition);
  369. }
  370. /**
  371. * 取得订单数量
  372. * @access public
  373. * @author csdeshang
  374. * @param array $condition 条件
  375. * @return int
  376. */
  377. public function getOrderCount($condition)
  378. {
  379. return Db::name('order')->where($condition)->count();
  380. }
  381. /**
  382. * 取得订单商品表详细信息
  383. * @access public
  384. * @author csdeshang
  385. * @param array $condition 条件
  386. * @param string $fields 字段
  387. * @param string $order 排序
  388. * @return array
  389. */
  390. public function getOrdergoodsInfo($condition = array(), $fields = '*', $order = '')
  391. {
  392. return Db::name('ordergoods')->where($condition)->field($fields)->order($order)->find();
  393. }
  394. /**
  395. * 取得订单商品表列表
  396. * @access public
  397. * @author csdeshang
  398. * @param type $condition 条件
  399. * @param type $fields 字段
  400. * @param type $limit 限制
  401. * @param type $pagesize 分页
  402. * @param type $order 排序
  403. * @param type $group 分组
  404. * @param type $key 键
  405. * @return array
  406. */
  407. public function getOrdergoodsList($condition = array(), $fields = '*', $limit = 0, $pagesize = null, $order = 'rec_id desc', $group = null, $key = null)
  408. {
  409. if ($pagesize) {
  410. $res = Db::name('ordergoods')->field($fields)->where($condition)->order($order)->group($group)->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  411. $this->page_info = $res;
  412. $ordergoods = $res->items();
  413. if (!empty($key)) {
  414. $ordergoods = ds_change_arraykey($ordergoods, $key);
  415. }
  416. return $ordergoods;
  417. } else {
  418. $ordergoods = Db::name('ordergoods')->field($fields)->where($condition)->limit($limit)->order($order)->group($group)->select()->toArray();
  419. if (!empty($key)) {
  420. $ordergoods = ds_change_arraykey($ordergoods, $key);
  421. }
  422. return $ordergoods;
  423. }
  424. }
  425. /**
  426. * 取得订单扩展表列表
  427. * @access public
  428. * @author csdeshang
  429. * @param array $condition 条件
  430. * @param string $fields 字段
  431. * @param string $order 排序
  432. * @param int $limit 限制
  433. * @return array
  434. */
  435. public function getOrdercommonList($condition = array(), $fields = '*', $order = '', $limit = 0)
  436. {
  437. return Db::name('ordercommon')->field($fields)->where($condition)->order($order)->limit($limit)->select()->toArray();
  438. }
  439. /**
  440. * 插入订单支付表信息
  441. * @access public
  442. * @author csdeshang
  443. * @param array $data 参数内容
  444. * @return int 返回 insert_id
  445. */
  446. public function addOrderpay($data)
  447. {
  448. return Db::name('orderpay')->insertGetId($data);
  449. }
  450. /**
  451. * 插入订单表信息
  452. * @access public
  453. * @author csdeshang
  454. * @param array $data 参数内容
  455. * @return int 返回 insert_id
  456. */
  457. public function addOrder($data)
  458. {
  459. $result = Db::name('order')->insertGetId($data);
  460. if ($result) {
  461. //更新缓存
  462. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'delOrderCountCache', 'cron_value' => serialize(array('buyer_id' => $data['buyer_id'], 'store_id' => $data['store_id']))));
  463. }
  464. return $result;
  465. }
  466. /**
  467. * 插入订单扩展表信息
  468. * @access public
  469. * @author csdeshang
  470. * @param array $data 参数内容
  471. * @return int 返回 insert_id
  472. */
  473. public function addOrdercommon($data)
  474. {
  475. return Db::name('ordercommon')->insertGetId($data);
  476. }
  477. /**
  478. * 插入订单扩展表信息
  479. * @access public
  480. * @author csdeshang
  481. * @param array $data 参数内容
  482. * @return int 返回 insert_id
  483. */
  484. public function addOrdergoods($data)
  485. {
  486. return Db::name('ordergoods')->insertAll($data);
  487. }
  488. /**
  489. * 添加订单日志
  490. * @access public
  491. * @author csdeshang
  492. * @param type $data 数据信息
  493. * @return type
  494. */
  495. public function addOrderlog($data)
  496. {
  497. $data['log_role'] = str_replace(array('buyer', 'seller', 'system', 'admin'), array('买家', '商家', '系统', '管理员'), $data['log_role']);
  498. $data['log_time'] = TIMESTAMP;
  499. return Db::name('orderlog')->insertGetId($data);
  500. }
  501. /**
  502. * 更改订单信息
  503. * @access public
  504. * @author csdeshang
  505. * @param array $data 数据
  506. * @param array $condition 条件
  507. * @param int $limit 限制
  508. * @return bool
  509. */
  510. public function editOrder($data, $condition, $limit = 0)
  511. {
  512. $update = Db::name('order')->where($condition)->limit($limit)->update($data);
  513. if ($update) {
  514. //更新缓存
  515. $order_list = Db::name('order')->where($condition)->select()->toArray();
  516. foreach ($order_list as $key => $order) {
  517. model('cron')->addCron(array('cron_exetime' => TIMESTAMP, 'cron_type' => 'delOrderCountCache', 'cron_value' => serialize(array('buyer_id' => $order['buyer_id'], 'store_id' => $order['store_id']))));
  518. }
  519. }
  520. return $update;
  521. }
  522. /**
  523. * 更改订单信息
  524. * @access public
  525. * @author csdeshang
  526. * @param array $data 数据
  527. * @param array $condition 条件
  528. * @return bool
  529. */
  530. public function editOrdercommon($data, $condition)
  531. {
  532. return Db::name('ordercommon')->where($condition)->update($data);
  533. }
  534. /**
  535. * 更改订单信息
  536. * @param unknown_type $data
  537. * @param unknown_type $condition
  538. */
  539. public function editOrdergoods($data, $condition)
  540. {
  541. return Db::name('ordergoods')->where($condition)->update($data);
  542. }
  543. /**
  544. * 更改订单支付信息
  545. * @access public
  546. * @author csdeshang
  547. * @param type $data 数据
  548. * @param type $condition 条件
  549. * @return type
  550. */
  551. public function editOrderpay($data, $condition)
  552. {
  553. return Db::name('orderpay')->where($condition)->update($data);
  554. }
  555. /**
  556. * 订单操作历史列表
  557. * @access public
  558. * @author csdeshang
  559. * @param type $condition 条件
  560. * @return Ambigous <multitype:, unknown>
  561. */
  562. public function getOrderlogList($condition)
  563. {
  564. return Db::name('orderlog')->where($condition)->select()->toArray();
  565. }
  566. /**
  567. * 取得单条订单操作记录
  568. * @access public
  569. * @author csdeshang
  570. * @param array $condition 条件
  571. * @param string $order 排序
  572. * @return array
  573. */
  574. public function getOrderlogInfo($condition = array(), $order = '')
  575. {
  576. return Db::name('orderlog')->where($condition)->order($order)->find();
  577. }
  578. /**
  579. * 返回是否允许某些操作
  580. * @access public
  581. * @author csdeshang
  582. * @param type $operate 操作
  583. * @param type $order_info 订单信息
  584. * @return boolean
  585. */
  586. public function getOrderOperateState($operate, $order_info)
  587. {
  588. if (!is_array($order_info) || empty($order_info))
  589. return false;
  590. switch ($operate) {
  591. //买家取消订单
  592. case 'buyer_cancel':
  593. $state = ($order_info['order_state'] == ORDER_STATE_NEW) ||
  594. ($order_info['order_state'] == ORDER_STATE_DEPOSIT) ||
  595. ($order_info['order_state'] == ORDER_STATE_REST) ||
  596. ($order_info['payment_code'] == 'offline' && $order_info['order_state'] == ORDER_STATE_PAY);
  597. break;
  598. //申请退款
  599. case 'refund_cancel':
  600. if (isset($order_info['refund'])) {
  601. $state = $order_info['refund'] == 1 && !intval($order_info['lock_state']);
  602. if ($order_info['ob_no']) { //已结算不可以退款
  603. $state = FALSE;
  604. }
  605. } else {
  606. $state = FALSE;
  607. }
  608. break;
  609. //商家取消订单
  610. case 'store_cancel':
  611. $state = ($order_info['order_state'] == ORDER_STATE_NEW) ||
  612. ($order_info['order_state'] == ORDER_STATE_DEPOSIT) ||
  613. ($order_info['order_state'] == ORDER_STATE_REST) ||
  614. ($order_info['payment_code'] == 'offline' &&
  615. in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND)));
  616. break;
  617. //平台取消订单
  618. case 'system_cancel':
  619. $state = ($order_info['order_state'] == ORDER_STATE_NEW) ||
  620. ($order_info['order_state'] == ORDER_STATE_DEPOSIT) ||
  621. ($order_info['order_state'] == ORDER_STATE_REST) ||
  622. ($order_info['payment_code'] == 'offline' && $order_info['order_state'] == ORDER_STATE_PAY);
  623. break;
  624. //平台收款
  625. case 'system_receive_pay':
  626. $state = ($order_info['order_state'] == ORDER_STATE_NEW || $order_info['order_state'] == ORDER_STATE_DEPOSIT || $order_info['order_state'] == ORDER_STATE_REST) && $order_info['payment_code'] != 'offline';
  627. break;
  628. //买家投诉
  629. case 'complain':
  630. $state = in_array($order_info['order_state'], array(ORDER_STATE_PAY, ORDER_STATE_SEND)) ||
  631. intval($order_info['finnshed_time']) > (TIMESTAMP - config('ds_config.complain_time_limit'));
  632. break;
  633. case 'payment':
  634. $state = $order_info['order_state'] == ORDER_STATE_NEW && $order_info['payment_code'] == 'online';
  635. break;
  636. //调整运费
  637. case 'modify_price':
  638. $state = ($order_info['order_state'] == ORDER_STATE_NEW) || ($order_info['payment_code'] == 'offline' && $order_info['order_state'] == ORDER_STATE_PAY);
  639. $state = floatval($order_info['shipping_fee']) > 0 && $state;
  640. break;
  641. //调整商品价格
  642. case 'spay_price':
  643. $state = ($order_info['order_state'] == ORDER_STATE_NEW) ||
  644. ($order_info['payment_code'] == 'offline' && $order_info['order_state'] == ORDER_STATE_PAY);
  645. $state = floatval($order_info['goods_amount']) > 0 && $state;
  646. break;
  647. //发货
  648. case 'send':
  649. $state = !$order_info['lock_state'] && $order_info['order_state'] == ORDER_STATE_PAY;
  650. break;
  651. //收货
  652. case 'receive':
  653. $state = !$order_info['lock_state'] && $order_info['order_state'] == ORDER_STATE_SEND;
  654. break;
  655. //评价
  656. case 'evaluation':
  657. $state = !$order_info['refund_state'] && !$order_info['lock_state'] && !$order_info['evaluation_state'] && $order_info['order_state'] == ORDER_STATE_SUCCESS;
  658. break;
  659. //锁定
  660. case 'lock':
  661. $state = intval($order_info['lock_state']) ? true : false;
  662. break;
  663. //快递跟踪
  664. case 'deliver':
  665. $state = !empty($order_info['shipping_code']) && in_array($order_info['order_state'], array(ORDER_STATE_SEND, ORDER_STATE_SUCCESS));
  666. break;
  667. //放入回收站
  668. case 'delete':
  669. $state = in_array($order_info['order_state'], array(ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS)) && $order_info['delete_state'] == 0;
  670. break;
  671. //永久删除、从回收站还原
  672. case 'drop':
  673. case 'restore':
  674. $state = in_array($order_info['order_state'], array(ORDER_STATE_CANCEL, ORDER_STATE_SUCCESS)) && $order_info['delete_state'] == 1;
  675. break;
  676. }
  677. return $state;
  678. }
  679. /**
  680. * 联查订单表订单商品表
  681. * @access public
  682. * @author csdeshang
  683. * @param array $condition 条件
  684. * @param string $field 站点
  685. * @param number $pagesize 分页
  686. * @param string $order 排序
  687. * @return array
  688. */
  689. public function getOrderAndOrderGoodsList($condition, $field = '*', $pagesize = 0, $order = 'rec_id desc')
  690. {
  691. if ($pagesize) {
  692. $list = Db::name('ordergoods')->alias('order_goods')->where($condition)->field($field)->join('order order', 'order_goods.order_id=order.order_id', 'LEFT')->paginate(['list_rows' => $pagesize, 'query' => request()->param()], false);
  693. $this->page_info = $list;
  694. return $list->items();
  695. } else {
  696. $list = Db::name('ordergoods')->alias('order_goods')->where($condition)->field($field)->join('order order', 'order_goods.order_id=order.order_id', 'LEFT')->select()->toArray();
  697. return $list;
  698. }
  699. }
  700. /**
  701. * 订单销售记录 订单状态为20、30、40时
  702. * @access public
  703. * @author csdeshang
  704. * @param unknown $condition 条件
  705. * @param string $field 字段
  706. * @param number $pagesize 分页
  707. * @param string $order 排序
  708. * @return array
  709. */
  710. public function getOrderAndOrderGoodsSalesRecordList($condition, $field = "*", $pagesize = 0, $order = 'rec_id desc')
  711. {
  712. $condition[] = array('order_state', 'in', array(ORDER_STATE_PAY, ORDER_STATE_SEND, ORDER_STATE_SUCCESS));
  713. return $this->getOrderAndOrderGoodsList($condition, $field, $pagesize, $order);
  714. }
  715. }