|
@@ -0,0 +1,200 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\controller;
|
|
|
+
|
|
|
+use app\common\controller\Backend;
|
|
|
+use Think\Db;
|
|
|
+use wxpay;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 活动报名管理
|
|
|
+ *
|
|
|
+ * @icon fa fa-circle-o
|
|
|
+ */
|
|
|
+class Activeorder extends Backend
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Activeorder模型对象
|
|
|
+ * @var \app\admin\model\Activeorder
|
|
|
+ */
|
|
|
+ protected $model = null;
|
|
|
+
|
|
|
+ public function _initialize()
|
|
|
+ {
|
|
|
+ parent::_initialize();
|
|
|
+ $this->model = new \app\admin\model\Activeorder;
|
|
|
+ $this->view->assign("paytypeList", $this->model->getPaytypeList());
|
|
|
+ $this->view->assign("statusList", $this->model->getStatusList());
|
|
|
+ $this->view->assign("refundstatusList", $this->model->getRefundstatusList());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ $active_id = input('active_id', 0, 'intval'); //活动id
|
|
|
+ if (!$active_id) {
|
|
|
+ $active_id = input('ids', 0, 'intval'); //从活动列表第一次跳转过来
|
|
|
+ }
|
|
|
+ $this->assignconfig('active_id', $active_id);
|
|
|
+
|
|
|
+ //查询活动状态
|
|
|
+ $active_status = Db::name('active')->where(['id' => $active_id])->value('status'); //状态:0=报名中,1=已成行,2=已结束,3=已取消
|
|
|
+ $this->assignconfig('active_status', $active_status);
|
|
|
+
|
|
|
+ //当前是否为关联查询
|
|
|
+ $this->relationSearch = true;
|
|
|
+ //设置过滤方法
|
|
|
+ $this->request->filter(['strip_tags', 'trim']);
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
+
|
|
|
+ $list = $this->model
|
|
|
+ ->with(['active','user'])
|
|
|
+ ->where(['active_id' => $active_id])
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->paginate($limit);
|
|
|
+
|
|
|
+ foreach ($list as $row) {
|
|
|
+
|
|
|
+ $row->getRelation('active')->visible(['title','desc']);
|
|
|
+ $row->getRelation('user')->visible(['nickname','mobile']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $result = array("total" => $list->total(), "rows" => $list->items());
|
|
|
+
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退款
|
|
|
+ */
|
|
|
+ public function refund() {
|
|
|
+ $ids = input('ids', 0, 'intval'); //订单id
|
|
|
+
|
|
|
+ if (!$ids) {
|
|
|
+ $this->error('参数缺失');
|
|
|
+ }
|
|
|
+
|
|
|
+ $info = Db::name('active_order')->find($ids);
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('订单不存在');
|
|
|
+ }
|
|
|
+ //查询活动
|
|
|
+ $active_info = Db::name('active')->find($info['active_id']);
|
|
|
+ if (!$active_info) {
|
|
|
+ $this->error('活动不存在');
|
|
|
+ }
|
|
|
+ if ($active_info['status'] != 3) {
|
|
|
+ $this->error('当前活动状态不能手动退款');
|
|
|
+ }
|
|
|
+ if ($info['status'] != 1 && $info['refundstatus'] != 2) {
|
|
|
+ $this->error('当前订单状态不能手动退款');
|
|
|
+ }
|
|
|
+
|
|
|
+ //开启事务
|
|
|
+ Db::startTrans();
|
|
|
+ //修改活动人员状态
|
|
|
+ $people_rs = Db::name('active_people')->where(['order_id' => $ids, 'status' => 1])->setField(['status' => 3, 'modifystatus' => 0, 'updatetime' => time()]);
|
|
|
+ if ($people_rs === false) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+ //修改活动人员信息修改表
|
|
|
+ $people_modify_rs = Db::name('active_people_modify')->where(['order_id' => $ids, 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
|
|
|
+ if ($people_modify_rs === false) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+ //修改活动申请取消表
|
|
|
+ $refund_rs = Db::name('active_refund')->where(['order_id' => $ids, 'status' => 0])->setField(['status' => 2, 'updatetime' => time()]);
|
|
|
+ if ($refund_rs === false) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+ //查询活动订单
|
|
|
+ $active_order = Db::name('active_order'); //活动订单表
|
|
|
+ $user_coupon = Db::name('user_coupon'); //用户优惠券表
|
|
|
+ $sys_msg = Db::name('sys_msg'); //消息通知
|
|
|
+
|
|
|
+ //活动订单修改信息
|
|
|
+ $order_data['status'] = 3; //状态:0=待付款,1=待出行,2=已完成,3=已取消
|
|
|
+ $order_data['updatetime'] = time();
|
|
|
+
|
|
|
+ //退还支付金额
|
|
|
+ if ($info['price'] > 0) {
|
|
|
+ $order_data['refundstatus'] = 1; //退款状态:0=无需退款,1=退款成功,2=退款失败
|
|
|
+ $order_data['refundprice'] = $info['price'];//退款金额
|
|
|
+ $order_data['refundtime'] = time();
|
|
|
+
|
|
|
+ if ($info['paytype'] == 0) {
|
|
|
+ //余额支付, 退回余额
|
|
|
+ $rs = create_log($info['price'], '活动取消返还', $info['user_id'], 3, $info['id']);
|
|
|
+ if ($rs != 1) {
|
|
|
+ $order_data['refundstatus'] = 2;
|
|
|
+ }
|
|
|
+ } elseif ($info['paytype'] == 1) {
|
|
|
+ //微信支付, 退回微信
|
|
|
+ //扣除用户成长值
|
|
|
+ $paygrowth = (int)config('site.paygrowth'); //每消费1元赠送成长值数量, 1元=?成长值
|
|
|
+ $balance = floor($paygrowth * $info['price']);
|
|
|
+ if ($balance > 0) {
|
|
|
+ $paygrowth_rs = create_growth_log(-$balance, '活动取消扣除', $info['user_id'], 4);
|
|
|
+ }
|
|
|
+ //退款单号
|
|
|
+ $order_data['refund_no'] = $info['order_sn'];
|
|
|
+ //调用微信退款
|
|
|
+ $wxData['transaction_id'] = $info['transaction_id'];
|
|
|
+ $wxData['out_refund_no'] = $order_data['refund_no'];
|
|
|
+ $wxData['total_fee'] = (int)($info['price'] * 100);//1 微信支付 单位为分
|
|
|
+ $wxData['refund_fee'] = (int)($info['price'] * 100);//1 微信支付 单位为分
|
|
|
+ $wxData['refund_desc'] = '活动取消返还';
|
|
|
+// require_once("Plugins/WxPay/WxPay.php");
|
|
|
+ $wxPay = new wxpay\WxPay(config('wxchatpay'));
|
|
|
+ $back = $wxPay->WxPayRefund($wxData);
|
|
|
+ if($back['return_code'] != 'SUCCESS' || $back['result_code'] != 'SUCCESS') {
|
|
|
+ $order_data['refundstatus'] = 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //修改活动订单状态
|
|
|
+ $order_rs = $active_order->where(['id' => $info['id'], 'status' => $info['status'], 'refundstatus' => $info['refundstatus']])->setField($order_data);
|
|
|
+ if ($order_rs === false) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('操作失败');
|
|
|
+ }
|
|
|
+ //上级优惠券设为过期
|
|
|
+ $user_coupon->where(['order_id' => $ids, 'status' => 0])->setField('endtime', time() - 1);
|
|
|
+ //发送消息
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $info['user_id'],
|
|
|
+ 'type' => 1,
|
|
|
+ 'title' => '活动通知',
|
|
|
+ 'content' => '您报名的' . $active_info['title'] . '活动已取消',
|
|
|
+ 'createtime' => time()
|
|
|
+ ];
|
|
|
+ $sys_msg->insertGetId($data);
|
|
|
+
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('退款成功');
|
|
|
+ }
|
|
|
+}
|