mall_id = $config['mall_id'] ?? 0; $this->user_id = $config['user_id'] ?? 0; } //查找用户 public function searchUser($params) { try { $where = [ ['mall_id' => $this->mall_id], ['status' => StatusEnum::ENABLED] ]; if (!empty($params['keyword'])) $where[] = ['or', ['like', 'id', $params['keyword']], ['like', 'nickname', $params['keyword']], ['like', 'mobile', $params['keyword']]]; //获取用户信息 $list = User::lists([ 'where' => $where, 'order' => 'id desc', 'limit' => 20, 'select' => 'id,nickname,username,mall_id,level,mobile,avatar_url', ]); if (!empty($list)) { foreach ($list as &$item) { $item['user_id'] = $item['id']; unset($item['id']); } } return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //给用户发放课程 public function giveUserCourse($params) { try { //生成订单 $orderno = AddonsCourseOrders::generateOrderNo('C'); //获取课程 $course_info = AddonsCourse::getOne([ ['mall_id' => $this->mall_id], ['id' => $params['id']], ['status' => StatusEnum::ENABLED] ], true); if (empty($course_info)) throw new Exception('查无此课程'); //查找是否用户已用户该课程 $user_course = AddonsCourseBought::getOne([ ['mall_id' => $this->mall_id], ['user_id' => $params['user_id']], ['course_id' => $params['id']], ['is_pay' => 1], ['status' => StatusEnum::ENABLED], ]); if (!empty($user_course)) throw new Exception('该用户已拥有该课程'); $params = [ 'mall_id' => $this->mall_id, 'user_id' => $params['user_id'], 'course_id' => $params['id'], 'order_no' => $orderno, 'price' => 0, 'pay_money' => 0, 'remark' => '后台发放', 'pay_type' => 0, 'order_status' => 1, 'use_discount' => 0, 'discount_type' => 0, 'discount_quota' => 0, ]; //记录订单 $res = AddonsCourseOrders::setData($params); if (!$res) throw new \Exception(AddonsCourseOrders::$static_error); //添加课程购买记录 $result = AddonsCourseBought::addBought($params, $res->id); if (!$result) throw new Exception(AddonsCourseBought::$static_error); return true; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //获取课程订单分佣数据 public function getCourseCommissionList($params) { try { $condition = [ 'where' => [ ['source_table' => [AddonsCourseOrders::tableName(), '%addons_course_orders']], ['source_table_id' => $params['order_id']], ['mall_id' => $this->mall_id], ], ]; // $wallet_type = $params['wallet_type']; CapitalLog::$capitalType = $params['wallet_type']; $list = CapitalLog::getList($condition, 0); return $list; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } //课程订单主动退款 public function doRefundSubmit($params) { try { //查看订单信息 $order_info = AddonsCourseOrders::getOne([ ['mall_id' => $this->mall_id], ['id' => $params['order_id']], ['refund_status' => [1, 2]], ]); if (!empty($order_info)) throw new Exception('该订单正在售后中,请勿重复操作'); AddonsCourseOrders::updateAll(['refund_status' => 1, 'refund_desc' => $params['remark']], ['mall_id' => $this->mall_id, 'id' => $params['order_id']]); $params['mall_id'] = $this->mall_id; $res = (new OrderRefuseLogic())->refuseOrder($params); return true; } catch (\Exception $e) { throw new Exception($e->getMessage()); } } }