BillApply.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. namespace app\synth\controller;
  3. use app\common\model\ActivityApply;
  4. use app\common\model\GoodsOrder;
  5. use app\common\model\LevelOrder;
  6. use app\common\model\StoreOrderRefund;
  7. use app\common\model\UserMessage;
  8. use library\Controller;
  9. use think\Db;
  10. class BillApply extends Controller
  11. {
  12. protected $table = 'BillApply';
  13. /**
  14. * 列表
  15. * @auth true
  16. * @menu true
  17. * @throws \think\Exception
  18. * @throws \think\db\exception\DataNotFoundException
  19. * @throws \think\db\exception\ModelNotFoundException
  20. * @throws \think\exception\DbException
  21. * @throws \think\exception\PDOException
  22. */
  23. public function index()
  24. {
  25. $this->title = '列表';
  26. $query = $this->_query($this->table);
  27. $this->type_arr = \app\common\model\BillType::getType();
  28. $where= [];
  29. $were[] = ['i.is_deleted','=',0];
  30. if($this->request->request('user_name')) $where[]= ['i.name','like','%'.$this->request->request('user_name').'%'];
  31. if($this->request->request('header')) $where[]= ['i.header','like','%'.$this->request->request('header').'%'];
  32. if($this->request->request('type')) $where[]= ['i.type','=',$this->request->request('type')];
  33. $query->alias('i')->field('i.* ,b.title type_name,m.headimg,m.name as user_name,m.phone')
  34. ->Leftjoin('store_member m',' m.id = i.user_id ')
  35. ->join('bill_type b',' b.id = i.type ','LEFT');
  36. if(!empty($where)) $query->where($where);
  37. $query ->order('i.id desc')->page();
  38. }
  39. protected function _index_page_filter(array &$data)
  40. {
  41. }
  42. /**
  43. * 删除
  44. * @auth true
  45. * @menu true
  46. * @param array $data
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\ModelNotFoundException
  49. * @throws \think\exception\DbException
  50. */
  51. public function remove()
  52. {
  53. $this->_save($this->table, ['is_deleted' => '1']);
  54. }
  55. /**
  56. * 编辑
  57. * @auth true
  58. * @menu true
  59. * @throws \think\Exception
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\ModelNotFoundException
  62. * @throws \think\exception\DbException
  63. * @throws \think\exception\PDOException
  64. */
  65. public function edit()
  66. {
  67. $this->title = '编辑';
  68. $this->_form($this->table, 'form');
  69. }
  70. /**
  71. * 表单数据处理
  72. * @auth true
  73. * @menu true
  74. * @param array $data
  75. */
  76. protected function _form_filter(&$data)
  77. {
  78. if ($this->request->isGet() && $this->request->action() == 'edit'){
  79. // 退款金额
  80. $refund_money = StoreOrderRefund::getRefundMoney($data['order_id'],1);
  81. $data['refund_money'] = $refund_money;
  82. if($data['order_type'] == 1) $order_info = LevelOrder::where('id',$data['order_id'])->find()->toArray();
  83. if($data['order_type'] == 2) $order_info = GoodsOrder::where('id',$data['order_id'])->find()->toArray();
  84. if($data['order_type'] == 3) $order_info = ActivityApply::where('id',$data['order_id'])->find()->toArray();
  85. $data['order_info'] = $order_info;
  86. $data['type_name'] = \app\common\model\BillType::where('id',$data['type'])->value('title');
  87. if($data['address_info']) $data['address_info'] = json_decode($data['address_info'],true);
  88. $this->data = $data;
  89. }
  90. if ($this->request->isPost() && $this->request->action() == 'deliver') {
  91. $express_company = Db::name('express_company')->field('id,express_title')->find($data['express_company_id']);
  92. $data['express_company_title'] = $express_company['express_title'] ? $express_company['express_title'] : '';
  93. $data['express_send_at'] = date("Y-m-d H:i:s");
  94. $data['express_state'] = 1;
  95. }
  96. }
  97. /**
  98. * 修改快递
  99. * @auth true
  100. * @throws \think\Exception
  101. * @throws \think\db\exception\DataNotFoundException
  102. * @throws \think\db\exception\ModelNotFoundException
  103. * @throws \think\exception\DbException
  104. * @throws \think\exception\PDOException
  105. */
  106. public function express()
  107. {
  108. if ($this->request->isGet()) {
  109. $where = ['is_deleted' => '0', 'status' => '1'];
  110. $this->expressList = Db::name('express_company')->where($where)->order('sort desc,id desc')->select();
  111. $info = \app\common\model\BillApply::where('id',input('id'))->find();
  112. if($info['address_info']) $info['address_info'] = json_decode($info['address_info'],true);
  113. $this->vo = $info;
  114. }
  115. $this->_form($this->table);
  116. }
  117. /**
  118. * 快递表单处理
  119. * @param array $vo
  120. * @throws \think\db\exception\DataNotFoundException
  121. * @throws \think\db\exception\ModelNotFoundException
  122. * @throws \think\exception\DbException
  123. */
  124. protected function _express_form_filter(&$vo)
  125. {
  126. if ($this->request->isPost()) {
  127. $order = Db::name($this->table)->where(['id' => $vo['id']])->find();
  128. if (empty($order)) $this->error('订单查询异常,请稍候再试!');
  129. $express = Db::name('express_company')->where(['express_code' => $vo['express_company_code']])->find();
  130. if (empty($express)) $this->error('发货快递公司异常,请重新选择快递公司!');
  131. $vo['express_company_title'] = $express['express_title'];
  132. $vo['express_send_at'] = empty($order['express_send_at']) ? date('Y-m-d H:i:s') : $order['express_send_at'];
  133. $vo['express_state'] = '1';
  134. $vo['status'] = '1';
  135. $vo['bill_time'] = date("Y-m-d H:i:s");
  136. $info = \app\common\model\BillApply::where('b.id', $vo['id'])->alias('b')->field('b.user_id,y.act_id')
  137. ->leftJoin('ActivityApply y','y.id = b.order_id')->find()->toArray();
  138. UserMessage::sendUserMessage($info['user_id'],'activity',5,1,0,$info['act_id'],'',$vo['id']);
  139. }
  140. }
  141. public function billImageSave()
  142. {
  143. if($this->request->isPost()) {
  144. $id = input('post.id');
  145. $bill_img = input('post.bill_img');
  146. \app\common\model\BillApply::where('id',$id)->update(['bill_img'=>$bill_img,'bill_time'=>date("Y-m-d H:i:s"),'status'=>1]);
  147. $info = \app\common\model\BillApply::where('b.id',$id)->alias('b')->field('b.user_id,y.act_id')
  148. ->leftJoin('ActivityApply y','y.id = b.order_id')->find()->toArray();
  149. UserMessage::sendUserMessage($info['user_id'],'activity',5,0,0,$info['act_id'],'',$id);
  150. $this->success('保存成功');
  151. }
  152. }
  153. }