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