Order.php 28 KB

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