| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- <?php
- namespace addons\Rebate\backend\controllers;
- use addons\Rebate\common\logic\RewardLogic;
- use addons\Rebate\common\models\Rebate;
- use addons\Rebate\common\models\RebateBuy;
- use addons\Rebate\common\models\RebateVirtualOrderLog;
- use common\models\base\User;
- use Yii;
- /**
- * 默认控制器
- *
- * Class DefaultController
- *
- * @package addons\Rebate\backend\controllers
- */
- class VirtualOrderController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isGet) {
- $params = Yii::$app->request->get();
- $time = time();
- $list = $where = [];
- $where[] = ['=', 'mall_id', $this->mall_id];
- if (isset($params['p_id']) && $params['p_id'] !== '') {
- $where[] = ['=', 'user_parent_id', $params['p_id']];
- }
- if (isset($params['id']) && $params['id'] !== '') {
- $where[] = ['=', 'user_id', $params['id']];
- }
- if (isset($params['mobile']) && $params['mobile'] !== '') {
- $userId = User::find()
- ->where([
- 'mobile' => $params['mobile'],
- 'mall_id' => $this->mall_id
- ])
- ->select('id')
- ->scalar();
- if (empty($userId)) {
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- $where[] = ['=', 'user_id', $userId];
- }
- if (isset($params['p_mobile']) && $params['p_mobile'] !== '') {
- $userId = User::find()
- ->where([
- 'mobile' => $params['p_mobile'],
- 'mall_id' => $this->mall_id
- ])
- ->select('id')
- ->scalar();
- if (empty($userId)) {
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- $where[] = ['=', 'user_parent_id', $userId];
- }
- if (isset($params['rebate_title']) && $params['rebate_title'] !== '') {
- $rebateId = Rebate::find()
- ->where([
- 'title' => $params['rebate_title'],
- 'mall_id' => $this->mall_id
- ])
- ->select('id')
- ->column();
- if (empty($rebateId)) {
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- $where[] = ['in', 'rebate_id', $rebateId];
- }
- if (isset($params['order_no']) && $params['order_no'] !== '') {
- $rebateBuyId = RebateBuy::find()
- ->where([
- 'order_no' => $params['order_no'],
- 'mall_id' => $this->mall_id
- ])
- ->select('id')
- ->scalar();
- if (empty($rebateBuyId)) {
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- $where[] = ['=', 'rebate_buy_id', $rebateBuyId];
- }
- $order = 'id desc';
- $select = 'id, user_id, user_parent_id, mall_id, rebate_id, rebate_buy_id, created_at';
- $with = [
- 'user' => function ($query) {
- $query->select('id, nickname, avatar_url, mobile');
- },
- 'parentUser' => function ($query) {
- $query->select('id, nickname, avatar_url, mobile');
- },
- 'rebate' => function ($query) {
- $query->select('id, title');
- },
- 'rebateBuy' => function ($query) {
- $query->select('id, order_no');
- }
- ];
- $params = compact('where', 'order', 'select', 'with');
- $list = RebateVirtualOrderLog::listPage($params, false, true);
- $this->success('获取成功', ['list' => $list, 'now_time' => $time]);
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- /**
- * 创建虚拟订单
- *
- * @return mixed|string|null
- */
- public function actionAdd()
- {
- if (Yii::$app->request->isAjax) {
- if (Yii::$app->request->isPost) {
- $params = Yii::$app->request->post();
- $res = Yii::$app->services->validate->validate($params, [
- [['user_id', 'rebate_id'], 'required'],
- [['user_id', 'rebate_id'], 'integer'],
- ]);
- if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- if (!RewardLogic::createVirtualOrder($this->mall_id, $params['user_id'], $params['rebate_id'])) {
- return $this->error(RewardLogic::getStaticError());
- }
- return $this->success("保存成功");
- }
- }
- return $this->render($this->action->id);
- }
- }
|