Order.php 29 KB

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