Order.php 29 KB

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