Order.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | framework
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://framework.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/framework
  12. // +----------------------------------------------------------------------
  13. namespace app\store\controller;
  14. use library\Controller;
  15. use think\Db;
  16. /**
  17. * 订单记录管理
  18. * Class Order
  19. * @package app\store\controller
  20. */
  21. class Order extends Controller
  22. {
  23. /**
  24. * 绑定数据表
  25. * @var string
  26. */
  27. protected $table = 'StoreOrder';
  28. /**
  29. * 订单记录管理
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. * @throws \think\exception\PDOException
  35. */
  36. public function index()
  37. {
  38. $this->title = '订单记录管理';
  39. $this->_query($this->table)->order('id desc')->page();
  40. }
  41. /**
  42. * 订单列表处理
  43. * @param array $data
  44. * @throws \think\db\exception\DataNotFoundException
  45. * @throws \think\db\exception\ModelNotFoundException
  46. * @throws \think\exception\DbException
  47. */
  48. protected function _index_page_filter(array &$data)
  49. {
  50. $goodsList = Db::name('StoreOrderList')->whereIn('order_no', array_unique(array_column($data, 'order_no')))->select();
  51. $mids = array_unique(array_merge(array_column($data, 'mid'), array_column($data, 'from_mid')));
  52. $memberList = Db::name('StoreMember')->whereIn('id', $mids)->select();
  53. foreach ($data as &$vo) {
  54. list($vo['member'], $vo['from_member'], $vo['list']) = [[], [], []];
  55. foreach ($goodsList as $goods) if ($goods['order_no'] === $vo['order_no']) {
  56. $vo['list'][] = $goods;
  57. }
  58. foreach ($memberList as $member) if ($member['id'] === $vo['mid']) {
  59. $member['nickname'] = emoji_decode($member['nickname']);
  60. $vo['member'] = $member;
  61. }
  62. }
  63. }
  64. /**
  65. * 修改快递管理
  66. * @throws \think\db\exception\DataNotFoundException
  67. * @throws \think\db\exception\ModelNotFoundException
  68. * @throws \think\exception\DbException
  69. */
  70. public function express()
  71. {
  72. if ($this->request->isGet()) {
  73. $where = ['is_deleted' => '0', 'status' => '1'];
  74. $this->expressList = Db::name('StoreExpress')->where($where)->order('sort asc,id desc')->select();
  75. }
  76. $this->_form($this->table);
  77. }
  78. /**
  79. * 快递追踪查询
  80. */
  81. public function expressQuery()
  82. {
  83. list($code, $no) = [input('code', ''), input('no', '')];
  84. if (empty($no)) $this->error('快递编号不能为空!');
  85. if (empty($code)) $this->error('快递公司编码不能为空!');
  86. $this->result = \library\tools\Express::query($code, $no);
  87. $this->fetch();
  88. }
  89. /**
  90. * 快递表单处理
  91. * @param array $vo
  92. * @throws \think\db\exception\DataNotFoundException
  93. * @throws \think\db\exception\ModelNotFoundException
  94. * @throws \think\exception\DbException
  95. */
  96. protected function _express_form_filter(&$vo)
  97. {
  98. if ($this->request->isPost()) {
  99. $order = Db::name($this->table)->where(['id' => $vo['id']])->find();
  100. if (empty($order)) $this->error('订单查询异常,请稍候再试!');
  101. $express = Db::name('StoreExpress')->where(['express_code' => $vo['express_company_code']])->find();
  102. if (empty($express)) $this->error('发货快递公司异常,请重新选择快递公司!');
  103. $vo['express_company_title'] = $express['express_title'];
  104. $vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at'];
  105. $vo['express_state'] = '1';
  106. $vo['status'] = '4';
  107. }
  108. }
  109. }