123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- <?php
- /**
- * 提成管理Controller
- * Created by PhpStorm.
- * User: haoren
- * Date: 2021/03/25
- * Time: 16:00
- */
- namespace JinDouYun\Controller\Reward;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Reward\MReward;
- class Reward extends BaseController
- {
- private $objMReward;
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMReward = new MReward($this->onlineEnterpriseId, $this->onlineUserId);
- }
- /**
- * 获取参数
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'staff' => isset($params['staff']) ? $params['staff'] : [],
- ];
- foreach($data as $key => $value){
- if(empty($value)){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- !empty($this->shopId) && $data['shopId'] = $this->shopId;
- isset($params['computed']) && $data['computed'] = !empty($params['computed']) ? $params['computed'] : '';
- isset($params['title']) && $data['title'] = !empty($params['title']) ? $params['title'] : '';
- isset($params['percentage']) && $data['percentage'] = !empty($params['percentage']) ? $params['percentage'] : 0;
- isset($params['goods']) && $data['goods'] = !empty($params['goods']) ? json_encode($params['goods']) : null;
- return $data;
- }
- /**
- * 提成规则添加
- */
- public function addRewardRule()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMReward->addRewardRule($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 提成规则删除
- */
- public function deleteRewardRule()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMReward->deleteRewardRule(['id' => $id]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 提成规则禁用
- */
- public function enableRewardRule()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMReward->enableRewardRule($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 提成规则修改
- */
- public function updateRewardRule()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- parent::sendOutput('id参数为空', ErrorCode::$paramError);
- }
- $data = self::commonFieldFilter();
- $result = $this->objMReward->updateRewardRule($data, ['id' => $id]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 提成规则列表
- */
- public function getAllRewardRule()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
- $selectParams['limit'] = $pageParams['limit'];
- $selectParams['offset'] = $pageParams['offset'];
- if(isset($params['search']) && !empty($params['search'])){
- $selectParams['search'] = $params['search'];
- }
- if(isset($params['enableStatus']) && !empty($params['enableStatus'])){
- $selectParams['enableStatus'] = $params['enableStatus'];
- }
- if(isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])){
- $selectParams['star'] = $params['star'];
- $selectParams['end'] = $params['end'];
- }
- if(!empty($this->shopId)){
- $selectParams['shopId'] = $this->shopId;
- }
- $result = $this->objMReward->getAllRewardRule($selectParams);
- if ($result->isSuccess()) {
- $returnData = $result->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($result->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * 提成规则详情
- */
- public function getRewardRuleInfo()
- {
- $params['id'] = $this->request->param('request_id');
- if (empty($params['id'])) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $result = $this->objMReward->getRewardRuleInfo($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- }
|