123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- <?php
- /**
- * api分销商Controller
- * Created by PhpStorm.
- * User: haoren
- * Date: 2020/07/22
- * Time: 15:00
- */
- namespace JinDouYun\Controller\Commission;
- use Exception;
- use JinDouYun\Model\Commission\MCommissionGrade;
- use JinDouYun\Model\Commission\MCommissionOrder;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\StatusCode;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Model\Commission\MCommissionBusinessman;
- class ApiCommissionBusinessman extends BaseController
- {
- /**
- * @var MCommissionBusinessman
- */
- private $objMCommissionBusinessman;
- /**
- * @var MCommissionOrder
- */
- private $objMCommissionOrder;
- /**
- * ApiCommissionBusinessman constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @param bool $checkToken
- * @throws Exception
- */
- public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
- {
- parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
- $this->objMCommissionBusinessman = new MCommissionBusinessman($this->onlineEnterpriseId, $this->onlineUserId);
- $this->objMCommissionOrder = new MCommissionOrder($this->onlineEnterpriseId,$this->onlineUserId);
- }
- /**
- * 获取参数
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value) && $value !== 0){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- (isset($params['info']) && !empty($params['info'])) && $data['info'] = $params['info'];
- (isset($params['gradeId']) && !empty($params['gradeId'])) && $data['gradeId'] = $params['gradeId'];
- (isset($params['grade']) && !empty($params['grade'])) && $data['grade'] = $params['grade'];
- return $data;
- }
- /**
- * 申请分销商
- * @throws Exception
- */
- public function applicationBusinessman()
- {
- $data = self::commonFieldFilter();
- $modelResult = $this->objMCommissionBusinessman->addBusinessman($data);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 添加上下级关系
- * @throws Exception
- */
- public function relationshipBusinessman()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'businessmanId' => getArrayItem($params, 'businessmanId'),
- 'source' => getArrayItem($params, 'source'),
- ];
- foreach($data as $key => $value){
- if(empty($value) && $value !== 0){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $modelResult = $this->objMCommissionBusinessman->relationshipBusinessman($data);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 修改分销商
- * @throws Exception
- */
- public function updateBusinessman()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = self::commonFieldFilter();
- $modelResult = $this->objMCommissionBusinessman->updateBusinessman($data, ['id' => $id]);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 分销商详情
- */
- public function getInfoBusinessman()
- {
- $where['userCenterId'] = $this->onlineUserId;
- $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 查询分销商的所有下级
- * @throws Exception
- */
- public function getAllSub()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'id' => isset($params['id']) ? $params['id'] : '',
- 'level' => isset($params['level']) ? $params['level'] : '',
- 'page' => isset($params['page']) ? $params['page'] : '',
- 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
- ];
- foreach($data as $key => $value){
- if(empty($value) && $value !== 0){
- parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
- }
- }
- $pageParams = pageToOffset($params['page'],$params['pageSize']);
- $data['limit'] = $pageParams['limit'];
- $data['offset'] = $pageParams['offset'];
- $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- $returnData = $modelResult->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- 'subTotal' => $returnData['subTotal'],
- 'businessmanTotal' => $returnData['businessmanTotal'],
- 'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * 排行榜
- */
- public function commissionTop()
- {
- $modelResult = $this->objMCommissionBusinessman->statisticsCommissionThree();
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 等级说明
- */
- public function getAllGrade()
- {
- $modelResult = $this->objMCommissionBusinessman->getBusinessmanGradeInfo();
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * Doc: (des="分销中心订单列表")
- * User: XMing
- * Date: 2020/7/30
- * Time: 10:47 上午
- * @throws Exception
- */
- public function getCommissionOrder()
- {
- $params = $this->request->getRawJson();
- if(empty($params)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $pageParams = pageToOffset($params['page'] ? $params['page'] : 1, $params['pageSize'] ? $params['pageSize'] : 10);
- $params['limit'] = $pageParams['limit'];
- $params['offset'] = $pageParams['offset'];
- $modelResult = $this->objMCommissionOrder->getCommissionOrder($params);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- $returnData = $modelResult->getData();
- $pageData = [
- 'pageIndex' => $params['page'],
- 'pageSize' => $params['pageSize'],
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- }
- /**
- * Doc: (des="分销订单详情")
- * User: XMing
- * Date: 2020/7/30
- * Time: 4:06 下午
- * @throws Exception
- */
- public function getCommissionOrderInfo()
- {
- $id = $this->request->param('request_id');
- if(empty($id)){
- parent::sendOutput('参数为空', ErrorCode::$paramError);
- }
- $modelResult = $this->objMCommissionOrder->getCommissionOrderInfo($id);
- if(!$modelResult->isSuccess()){
- parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
- }
- parent::sendOutput($modelResult->getData());
- }
- /**
- * 修改直系上级关系
- * @throws Exception
- * 客户id,上级id
- */
- public function editRelationship()
- {
- $params = $this->request->getRawJson();
- if(empty($params['id']) || empty($params['superiorId']) ){
- parent::sendOutput('分销商参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMCommissionBusinessman->editRelationship($params);
- if(!$result->isSuccess()){
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- }
|