BillApply.php 5.5 KB

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