123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- <?php
- namespace app\data\controller\shop;
- use app\data\model\DataUser;
- use app\data\model\ShopGoods;
- use app\data\model\ShopOrder;
- use app\data\model\ShopOrderPay;
- use app\data\model\ShopOrderSend;
- use app\data\service\OrderService;
- use app\data\service\PaymentService;
- use app\data\service\UserAdminService;
- use app\data\controller\api\business\Order;
- use think\admin\Controller;
- use think\admin\service\AdminService;
- class Refund extends Controller
- {
- /**
- * 支付方式
- * @var array
- */
- protected $payments = [];
- /**
- * 控制器初始化
- */
- protected function initialize()
- {
- parent::initialize();
- //$this->payments = PaymentService::getTypeAll();
- $this->payments = [
- [
- 'name'=>'支付宝支付'
- ],
- [
- 'name'=>'微信支付'
- ]
- ];
- // // 读取支付通道配置
- // $query = BaseUserPayment::mk()->where(['status' => 1, 'deleted' => 0]);
- // //$query->whereIn('code', str2arr($payments))->whereIn('type', PaymentService::getTypeApi($this->type));
- // $result = $query->order('sort desc,id desc')->column('type,code,name,cover,content,remark', 'code');
- // foreach ($result as &$vo) $vo['content'] = ['voucher_qrcode' => json_decode($vo['content'])->voucher_qrcode ?? ''];
- // $this->payments2 = array_values($result);
- // dump($this->payments2);
- }
- /**
- * 商品数据管理
- * @auth true
- * @menu true
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function index()
- {
- $this->title = '商品退款中';
- if(AdminService::getUserId()==10000){
- $admin_id = [];
- }
- else{
- $admin_id['admin_id']=AdminService::getUserId();
- }
- $where = [
- 'admin_id' => $admin_id,
- 'deleted_status' => 0,
- 'status' => 7
- ];
- $query = ShopOrder::mQuery()->where($where);
- //用户名账号查询
- $db = DataUser::mQuery()->like('phone|nickname#user_keys')->db();
- // print_r($db->getOptions('where'));
- // exit;
- if ($db->getOptions('where')) $query->whereRaw("uuid in {$db->field('id')->buildSql()}");
- //支付方式查询
- $query->like('order_no');
- $query->equal('payment_type');
- $query->order('id desc')->page();
- }
- /**
- * 订单列表处理
- * @param array $data
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- protected function _index_page_filter(array &$data)
- {
- UserAdminService::buildByUid($data);
- UserAdminService::buildByUid($data, 'puid1', 'from');
- OrderService::buildData($data);
- foreach ($data as &$vo) {
- if (!is_null($vo['payment_type']) and '' != $vo['payment_type']) {
- $vo['payment_name'] = PaymentService::name($vo['payment_type']);
- }
- }
- }
- /**
- * 退款
- */
- public function refund(){
- // print_r($this->_vali([
- // 'refund_status.require' => '状态值为空!',
- // 'id.require' => '状态值为空!',
- // 'type.require' => '状态值为空!'
- // ]));
- $this->refuse_dispose($this->_vali([
- 'refund_status.require' => '状态值为空!',
- 'id.require' => '状态值为空!',
- 'type.require' => '状态值为空!'
- ]));
- exit;
- // Order::examine_refund($type,$order_id,$type);
- }
- /**
- * 拒绝退款原因
- */
- public function refuse()
- {
- ShopOrder::mForm('refuse_form', 'id');
- }
- /**
- * 拒绝退款处理
- */
- protected function _refuse_form_filter(array &$vo)
- {
- if ($this->request->isPost()) {
- $this->refuse_dispose($vo);
- }
- }
- /**
- * 退款处理
- */
- public function refuse_dispose($data){
- $admin_id['admin_id']=AdminService::getUserId();
- $info = ShopOrder::mk()->where(['id'=>$data['id'],'admin_id'=>$admin_id['admin_id'],'status'=>7])->find();
- $pay_money = ShopOrderPay::mk()->where(['status' => 2, 'pay_no'=>$info['payment_trade']])->value('money');
- if(empty($info)){
- $this->error('订单信息有误');
- }
- else{
- // 退款操作
- if($data['type']==1){
- //同意退款
- if($info['payment_type']=='支付宝支付') {
- $result = json_decode(Order::refund_order($info['payment_trade'], $info['refund_money']), true);
- }
- if($info['payment_type']=='微信支付') {
- $result = json_decode(Order::wxrefund_order($info['payment_trade'], $info['refund_money'],$pay_money), true);
- }
- if($result) {
- 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')]);
- $this->success('已同意退款,支付金额原路退回');
- }
- else{
- $this->error('金额未退回查看支付账户');
- }
- }
- //统一退货
- else {
- 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')]);
- //不同意退款
- $this->success('已拒绝退款');
- }
- }
- }
- }
|