| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace addons\Sudoku\backend\controllers;
- use addons\Coupon\common\models\AddonsCoupon;
- use addons\Coupon\common\models\AddonsCouponUserRelate;
- use addons\Sudoku\common\models\AddonsSudoku;
- use common\enums\StatusEnum;
- use common\models\common\PlatformSetting;
- use common\models\user\User;
- use Yii;
- use common\controllers\AddonsController;
- use yii\db\Exception;
- /**
- * 默认控制器
- *
- * Class DefaultController
- * @package addons\Sudoku\backend\controllers
- */
- class DefaultController extends BaseController
- {
- public $enableCsrfValidation = false;
- /**
- * 首页
- *
- * @return string
- */
- public function actionIndex()
- {
- $retuest = Yii::$app->request;
- if ($retuest->isAjax) {
- if ($retuest->isPost) {
- $post = Yii::$app->request->post();
- // 检查提交的参数
- $res = Yii::$app->services->validate->validate($post,[
- [['list'], 'safe'],
- ]);
- if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage());
- $t = \Yii::$app->db->beginTransaction();
- try {
- $prize_ids = [];
- $params['where'][] = ['mall_id'=>$this->mall_id];
- $findData = AddonsSudoku::lists($params,true);
- if($findData) foreach ($findData as $v) $prize_ids[$v['prize_id']] = $v['id'];
- $post_type_list = array_column($post['list'],'type');
- if(!in_array(5,$post_type_list)){
- throw new \Exception('8个奖品至少选中一个谢谢参与');
- }
- foreach ($post['list'] as $k => $v){
- $v['mall_id'] = $this->mall_id;
- $v['created_at'] = time();
- if($prize_ids) $v['id'] = $prize_ids[$v['prize_id']];
- $res = AddonsSudoku::setData($v);
- if(!$res){
- throw new \Exception(AddonsSudoku::getStaticError());
- }
- }
- $t->commit();
- return $this->success('操作成功');
- }catch (\Exception $e) {
- $t->rollBack();
- return $this->success('操作失败,error:'.$e->getMessage());
- return false;
- }
- }
- if ($retuest->isGet) {
- $params['where'][] = ['mall_id'=>$this->mall_id];
- $params['order'] = 'id asc';
- $params['with'] = ['goods'];
- $list = AddonsSudoku::lists($params,true);
- $coupon_params['where'][] = ['mall_id' => $this->mall_id];
- $coupon_params['where'][] = ['status' => [StatusEnum::ENABLED, StatusEnum::DISABLED]];
- $coupon_params['order'] = 'sort asc,id desc';
- $coupon = AddonsCoupon::lists($coupon_params,true);
- $get_system_setting = PlatformSetting::getConfByGroup('system', true);
- $api_url = $get_system_setting['api_url']['value'];
- return $this->success('操作成功', compact('list','coupon','api_url'));
- }
- } else {
- return $this->render($this->action->id);
- }
- }
- public function actionLottery(){
- }
- }
|