BillApply.php 6.1 KB

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