123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- <?php
- namespace app\order\controller;
- use app\common\model\GoodsOrder;
- use app\common\model\OrderLogisticsUrge;
- use app\common\model\StoreOrderRefund;
- use app\common\model\UserMessage;
- use library\Controller;
- use library\tools\Data;
- use think\Db;
- use app\common\model\GoodsOrderItem;
- /**
- * 商品订单
- * Class StoreOrder
- * @package app\order\controller
- */
- class StoreOrder extends Controller
- {
- protected $table = 'StoreOrder';
- /**
- * 订单列表
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function index()
- {
- $this->title = '订单管理';
- $this->order_status = [0=>'待支付',1=>'已支付[待发货]',2=>'已发货[待收货]',3=>'已收货[待评论]',4=>'已完成',9=>'已取消'];
- $this->pay_state = ['待支付','已支付'];
- $this->all_pay_type = all_pay_type();
- $query = $this->_query($this->table);
- $where = [];
- $where[] = ['o.is_deleted','=',0];
- if($this->request->request('tel'))$where[]= ['u.phone','like','%'.$this->request->request('tel').'%'];
- if($this->request->request('user_name'))$where[]= ['u.name','like','%'.$this->request->request('user_name').'%'];
- if($this->request->request('order_no')) $where[]= ['o.order_no','like','%'.$this->request->request('order_no').'%'];
- if($this->request->request('pay_state') > -1) $where[]= ['o.pay_state','=',$this->request->request('pay_state')];
- if($this->request->request('order_status') > -1) $where[]= ['o.status','=',$this->request->request('order_status')];
- //->join('order_logistics_urge g',' o.id = g.order_id ','RIGHT')
- $query->alias('o')
- ->field('o.* , u.name ,u.phone as user_phone,u.headimg')
- ->join('store_member u',' o.user_id = u.id ','LEFT');
- $arr = ['is_new' => 0];
- \app\common\model\GoodsOrder::alias('f')->where('is_new',1)->update($arr);
- if(!empty($where)) $query->where($where);
- $query ->order('o.id desc')->page();
- }
- /**
- * 订单列表处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _index_page_filter(array &$data)
- {
- foreach ($data as &$vo) {
- $vo['item_list'] = GoodsOrderItem::field('i.num,i.sell_price,g.name,i.goods_spec')
- ->alias('i')
- ->where(['i.order_id'=>$vo['id']])
- ->leftJoin('StoreGoods g','g.id = i.goods_id')
- ->select();
- $vo['refund_info'] = StoreOrderRefund::where('order_id',$vo['id'])->where('order_type',2)->where('status','in','0,1,2,3,4')->find();
- $vo['logistics_urge'] = OrderLogisticsUrge::where('order_id',$vo['id'])->find();
- }
- }
- /**
- * 修改快递
- * @auth true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function express()
- {
- if ($this->request->isGet()) {
- $where = ['is_deleted' => '0', 'status' => '1'];
- $this->expressList = Db::name('express_company')->where($where)->order('sort desc,id desc')->select();
- }
- $this->_form($this->table);
- }
- /**
- * 快递表单处理
- * @param array $vo
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- protected function _express_form_filter(&$vo)
- {
- if ($this->request->isPost()) {
- $order = Db::name($this->table)->where(['id' => $vo['id']])->find();
- if (empty($order)) $this->error('订单查询异常,请稍候再试!');
- $express = Db::name('express_company')->where(['express_code' => $vo['express_company_code']])->find();
- if (empty($express)) $this->error('发货快递公司异常,请重新选择快递公司!');
- $vo['express_company_title'] = $express['express_title'];
- $vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at'];
- $vo['express_state'] = '1';
- $vo['status'] = '2';
- UserMessage::sendUserMessage($order['user_id'],'mall',2,0,0,$order['id'],'您的订单已发货',$order['id']);
- }
- }
- /**
- * 订单详情
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function detail()
- {
- $this->title = '订单详情';
- $this->_form($this->table);
- }
- /**
- * 订单发货
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function deliver()
- {
- $this->title = '发货';
- $this->express_company = Db::name('express_company')->field('id,express_title')->select();
- $this->_form($this->table,'deliver');
- }
- /**
- * 表单数据处理
- * @auth true
- * @menu true
- * @param array $data
- */
- protected function _form_filter(&$data)
- {
- if ($this->request->isGet() && $this->request->action() == 'detail'){
- $this->order_item = GoodsOrderItem::where(['o.order_id'=>$data['id']])
- ->alias('o')
- ->field('o.*,g.name,g.cover')
- ->leftJoin('StoreGoods g','g.id=o.goods_id')
- ->select()->toArray();
- $this->data = $data;
- }
- if ($this->request->isPost() && $this->request->action() == 'deliver') {
- $express_company = Db::name('express_company')->field('id,express_title')->find($data['express_company_id']);
- $data['express_company_title'] = $express_company['express_title'] ? $express_company['express_title'] : '';
- $data['express_send_at'] = date("Y-m-d H:i:s");
- $data['express_state'] = 1;
- $order_info= GoodsOrder::field('id,user_id')->where('id',$data['id'])->find()->toArray();
- //UserMessage::sendUserMessage($order_info['user_id'],'feedback',2,0,0,$data['id'],'订单已发货');
- UserMessage::create(['user_id'=>$order_info['user_id'],'type_id'=>2,'relation_id'=>$order_info['id'],'content'=>'订单已发货']);
- }
- }
- /**
- * 删除
- * @auth true
- * @menu true
- * @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function remove()
- {
- $this->_save($this->table, ['is_deleted' =>1]);
- }
- }
|