AdminOrderController.php 7.9 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <bronet@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;

use app\portal\service\ToolsService;
use cmf\controller\AdminBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;

class AdminOrderController extends AdminBaseController
{
    public function index()
    {
        $param = $this->request->param();
        $where = [];
        $keywordComplex = [];
        if (!empty($param['keyword'])) {
            $keywordComplex['o.mobile|u.user_nickname'] = ['like', "%" . $param['keyword'] . "%"];
        }
        if (!empty($param['status'])) {
            $where['o.status'] = $param['status'];
        }
        $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
        $endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
        if (!empty($startTime) && !empty($endTime)) {
            $where['o.create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
        } else {
            if (!empty($startTime)) {
                $where['o.create_time'] = ['>= time', $startTime];
            }
            if (!empty($endTime)) {
                $where['o.create_time'] = ['<= time', $endTime];
            }
        }

        $data = Db::name('order')
            ->alias('o')
            ->join('user u', 'o.user_id=u.id')
            ->join('post p', 'o.post_id=p.id')
            ->join('skill s', 'o.skill_id=s.id')
            ->join('category c', 's.category_id=c.id')
            ->join('user u2', 'p.user_id=u2.id')
            ->whereOr($keywordComplex)
            ->where($where)
            ->order('o.create_time', 'desc')
            ->field('o.*,u.user_nickname,p.user_id as puser_id,u2.user_nickname as puser_nickname,s.price,c.name,p.mobile as pmobile')
            ->paginate(10);
//        var_dump($data);
        $data->appends($param);
//111
        $this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
        $this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
        $this->assign('status', isset($param['status']) ? $param['status'] : '');
        $this->assign('page', $data->render());
        $this->assign('list', $data);
        return $this->fetch('index');
    }

    public function check()
    {
        $param = $this->request->param();
        $data = Db::name('order')->where('id', $param['id'])->find();
        $data['proof'] = json_decode($data['proof'], true);
        $this->assign('list', $data);
        return $this->fetch('check');
    }

    public function checkPost()
    {
        $param = $this->request->param();
        $order = Db::name('order')->where('id', $param['id'])->find();
        if ($param['status'] == 1) {
            Db::name('order')->where('id', $param['id'])->update(['status' => 7, 'to_user_status' => 4, 'to_post_status' => 4, 'remark' => $param['remark']]);
            $post_id = $order['post_id'];
            $mobile = Db::name('post')->where('id', $post_id)->find()['mobile'];
            $curl = curl_init();
            $url = 'https://api.zhuanxinyun.com/api/v2/sendSms.json?appKey=1luqgyqudbfwkjp64ge7cg5v0fscenir&appSecret=813ff35dc46bfd193d44d85499e7273c3834&phones='.$mobile.'&content=【达人组局】你所提交的订单完成申请已通过审核,可以在待提现中提现';
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 60);
            curl_setopt($curl, CURLOPT_URL, $url);
            $re=curl_exec($curl);
//            var_dump($re);
//            exit();
        }
        if ($param['status'] == 2 && $order['status'] == 3) {
            Db::name('order')->where('id', $param['id'])->update(['status' => 4, 'to_post_status' => 6, 'remark' => $param['remark']]);
            $post_id = $order['post_id'];
            $mobile = Db::name('post')->where('id', $post_id)->find()['mobile'];
            $curl = curl_init();
            $url = 'https://api.zhuanxinyun.com/api/v2/sendSms.json?appKey=1luqgyqudbfwkjp64ge7cg5v0fscenir&appSecret=813ff35dc46bfd193d44d85499e7273c3834&phones='.$mobile.'&content=【达人组局】你提交的订单完成申请未通过审核,请按照要求再次提交证据审核,第二次提交驳回订单费用将退还下单者';
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 60);
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_exec($curl);
        }
        if ($param['status'] == 2 && $order['status'] == 5) {
            $options = [
                'app_id' => config('app_id'),
                'secret' => config('app_secret'),
                'payment' => [
                    'merchant_id' => '1365052302',
                    'key' => 'ebfe7fba8f7a0fba3e19efcc547b956d',
                    'cert_path' => 'wechat/cert/apiclient_cert.pem', // XXX: 绝对路径!!!!
                    'key_path' => 'wechat/cert/apiclient_key.pem',      // XXX: 绝对路径!!!!
                    // 'device_info'     => '013467007045764',
                    // 'sub_app_id'      => '',
                    // 'sub_merchant_id' => '',
                    // ...
                ],
            ];
            $app = new Application($options);
            $payment = $app->payment;
            //使用商户订单号退款  PS.其他形式参考文档
            $orderNo = $order['order_sn'];//商户系统内部的订单号(out_trade_no)
            $refundNo = cmf_get_order_sn();//退款单号
            $result = $payment->refund($orderNo, $refundNo, $order['total_price'] * 100, $order['total_price'] * 100); // 总金额 100, 退款 80,refundFee可选(为空时全额退款)

            Db::name('refund')->insert(['type' => 1, 'order_sn' => $orderNo, 'create_time' => time(), 'money' => $order['total_price'], 'user_id' => $order['user_id']]);
            Db::name('order')->where('id', $param['id'])->update(['status' => 6, 'to_user_status' => 3, 'to_post_status' => 3, 'remark' => $param['remark']]);
        }
        $this->success('审核成功', url('AdminOrder/index'));
    }

    public function delete()
    {
        $param = $this->request->param();
        Db::name('order')->where('id', $param['id'])->delete();
        $this->success('删除成功');
    }

    public function mark()
    {
        $param = $this->request->param();
        $data = Db::name('order')->where('id', $param['id'])->find();
        $this->assign('list', $data);
        return $this->fetch();
    }

    public function markPost()
    {
        $param = $this->request->param();
        $data = Db::name('order')->where('id', $param['id'])->update($param);
        $this->success('备注成功', url('AdminOrder/index'));
    }


    public function contact(){
        $data=Db::name('contact_order')
            ->alias('co')
            ->join('post p', 'co.post_id=p.id')
            ->join('user u', 'co.user_id=u.id')
            ->join('user u2','p.user_id=u2.id')
            ->field('co.*,u.user_nickname,p.mobile,p.wx,u2.user_nickname as user_nickname2')
            ->where(['co.status'=>2])
            ->select();
        $this->assign('list',$data);
        return $this->fetch();
    }

    public function contactDelete(){
        $param=$this->request->param();
        Db::name('contact_order')->where('id',$param['id'])->delete();
        $this->success('删除成功');
    }
}