Refund.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. namespace app\data\controller\shop;
  3. use app\data\model\DataUser;
  4. use app\data\model\ShopGoods;
  5. use app\data\model\ShopOrder;
  6. use app\data\model\ShopOrderPay;
  7. use app\data\model\ShopOrderSend;
  8. use app\data\service\OrderService;
  9. use app\data\service\PaymentService;
  10. use app\data\service\UserAdminService;
  11. use app\data\controller\api\business\Order;
  12. use think\admin\Controller;
  13. use think\admin\service\AdminService;
  14. class Refund extends Controller
  15. {
  16. /**
  17. * 支付方式
  18. * @var array
  19. */
  20. protected $payments = [];
  21. /**
  22. * 控制器初始化
  23. */
  24. protected function initialize()
  25. {
  26. parent::initialize();
  27. //$this->payments = PaymentService::getTypeAll();
  28. $this->payments = [
  29. [
  30. 'name'=>'支付宝支付'
  31. ],
  32. [
  33. 'name'=>'微信支付'
  34. ]
  35. ];
  36. // // 读取支付通道配置
  37. // $query = BaseUserPayment::mk()->where(['status' => 1, 'deleted' => 0]);
  38. // //$query->whereIn('code', str2arr($payments))->whereIn('type', PaymentService::getTypeApi($this->type));
  39. // $result = $query->order('sort desc,id desc')->column('type,code,name,cover,content,remark', 'code');
  40. // foreach ($result as &$vo) $vo['content'] = ['voucher_qrcode' => json_decode($vo['content'])->voucher_qrcode ?? ''];
  41. // $this->payments2 = array_values($result);
  42. // dump($this->payments2);
  43. }
  44. /**
  45. * 商品数据管理
  46. * @auth true
  47. * @menu true
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function index()
  53. {
  54. $this->title = '商品退款中';
  55. if(AdminService::getUserId()==10000){
  56. $admin_id = [];
  57. }
  58. else{
  59. $admin_id['admin_id']=AdminService::getUserId();
  60. }
  61. $where = [
  62. 'admin_id' => $admin_id,
  63. 'deleted_status' => 0,
  64. 'status' => 7
  65. ];
  66. $query = ShopOrder::mQuery()->where($where);
  67. //用户名账号查询
  68. $db = DataUser::mQuery()->like('phone|nickname#user_keys')->db();
  69. // print_r($db->getOptions('where'));
  70. // exit;
  71. if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
  72. //支付方式查询
  73. $query->like('order_no');
  74. $query->equal('payment_type');
  75. $query->order('id desc')->page();
  76. }
  77. /**
  78. * 订单列表处理
  79. * @param array $data
  80. * @throws \think\db\exception\DataNotFoundException
  81. * @throws \think\db\exception\DbException
  82. * @throws \think\db\exception\ModelNotFoundException
  83. */
  84. protected function _index_page_filter(array &$data)
  85. {
  86. UserAdminService::buildByUid($data);
  87. UserAdminService::buildByUid($data, 'puid1', 'from');
  88. OrderService::buildData($data);
  89. foreach ($data as &$vo) {
  90. if (!is_null($vo['payment_type']) and '' != $vo['payment_type']) {
  91. $vo['payment_name'] = PaymentService::name($vo['payment_type']);
  92. }
  93. }
  94. }
  95. /**
  96. * 退款
  97. */
  98. public function refund(){
  99. // print_r($this->_vali([
  100. // 'refund_status.require' => '状态值为空!',
  101. // 'id.require' => '状态值为空!',
  102. // 'type.require' => '状态值为空!'
  103. // ]));
  104. $this->refuse_dispose($this->_vali([
  105. 'refund_status.require' => '状态值为空!',
  106. 'id.require' => '状态值为空!',
  107. 'type.require' => '状态值为空!'
  108. ]));
  109. exit;
  110. // Order::examine_refund($type,$order_id,$type);
  111. }
  112. /**
  113. * 拒绝退款原因
  114. */
  115. public function refuse()
  116. {
  117. ShopOrder::mForm('refuse_form', 'id');
  118. }
  119. /**
  120. * 拒绝退款处理
  121. */
  122. protected function _refuse_form_filter(array &$vo)
  123. {
  124. if ($this->request->isPost()) {
  125. $this->refuse_dispose($vo);
  126. }
  127. }
  128. /**
  129. * 退款处理
  130. */
  131. public function refuse_dispose($data){
  132. $admin_id['admin_id']=AdminService::getUserId();
  133. $info = ShopOrder::mk()->where(['id'=>$data['id'],'admin_id'=>$admin_id['admin_id'],'status'=>7])->find();
  134. $pay_money = ShopOrderPay::mk()->where(['status' => 2, 'pay_no'=>$info['payment_trade']])->value('money');
  135. if(empty($info)){
  136. $this->error('订单信息有误');
  137. }
  138. else{
  139. // 退款操作
  140. if($data['type']==1){
  141. //同意退款
  142. if($info['payment_type']=='支付宝支付') {
  143. $result = json_decode(Order::refund_order($info['payment_trade'], $info['refund_money']), true);
  144. }
  145. if($info['payment_type']=='微信支付') {
  146. $result = json_decode(Order::wxrefund_order($info['payment_trade'], $info['refund_money'],$pay_money), true);
  147. }
  148. if($result) {
  149. ShopOrder::mk()->where(['id' => $data['id'], 'admin_id' => $admin_id['admin_id']])->save(['status' => 8, 'refund_status' => 2, 'dk_time' => date('Y-m-d H:i:s')]);
  150. $this->success('已同意退款,支付金额原路退回');
  151. }
  152. else{
  153. $this->error('金额未退回查看支付账户');
  154. }
  155. }
  156. //统一退货
  157. else {
  158. ShopOrder::mk()->where(['id'=>$data['id'],'admin_id'=>$admin_id['admin_id']])->save(['status' => 4,'refund_status'=>3,'refuse_reason'=>$data['refuse_reason'],'dk_time'=>date('Y-m-d H:i:s')]);
  159. //不同意退款
  160. $this->success('已拒绝退款');
  161. }
  162. }
  163. }
  164. }