ApiCommissionBusinessman.Class.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <?php
  2. /**
  3. * api分销商Controller
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2020/07/22
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Controller\Commission;
  10. use Exception;
  11. use JinDouYun\Model\Commission\MCommissionGrade;
  12. use JinDouYun\Model\Commission\MCommissionOrder;
  13. use Mall\Framework\Core\ErrorCode;
  14. use Mall\Framework\Core\ResultWrapper;
  15. use Mall\Framework\Core\StatusCode;
  16. use JinDouYun\Controller\BaseController;
  17. use JinDouYun\Model\Commission\MCommissionBusinessman;
  18. use Util\Common\PartnerTools;
  19. use JinDouYun\Model\Customer\MCustomer;
  20. class ApiCommissionBusinessman extends BaseController
  21. {
  22. /**
  23. * @var MCommissionBusinessman
  24. */
  25. private $objMCommissionBusinessman;
  26. /**
  27. * @var MCommissionOrder
  28. */
  29. private $objMCommissionOrder;
  30. private $customerData;
  31. private $partnerTool;
  32. /**
  33. * ApiCommissionBusinessman constructor.
  34. * @param bool $isCheckAcl
  35. * @param bool $isMustLogin
  36. * @param bool $checkToken
  37. * @throws Exception
  38. */
  39. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken=true)
  40. {
  41. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  42. $this->objMCommissionBusinessman = new MCommissionBusinessman($this->onlineEnterpriseId, $this->onlineUserId);
  43. $this->objMCommissionOrder = new MCommissionOrder($this->onlineEnterpriseId,$this->onlineUserId);
  44. $this->partnerTool = new PartnerTools($this->onlineEnterpriseId);
  45. $this->customerData = $this->partnerTool->getCustomerDataByUserCenterId($this->onlineUserId);
  46. }
  47. /**
  48. * 获取参数
  49. */
  50. public function commonFieldFilter()
  51. {
  52. $params = $this->request->getRawJson();
  53. if (empty($params)) {
  54. parent::sendOutput('参数为空', ErrorCode::$paramError);
  55. }
  56. $data = [
  57. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  58. ];
  59. foreach($data as $key => $value){
  60. if(empty($value) && $value !== 0){
  61. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  62. }
  63. }
  64. (isset($params['info']) && !empty($params['info'])) && $data['info'] = $params['info'];
  65. (isset($params['gradeId']) && !empty($params['gradeId'])) && $data['gradeId'] = $params['gradeId'];
  66. (isset($params['grade']) && !empty($params['grade'])) && $data['grade'] = $params['grade'];
  67. return $data;
  68. }
  69. /**
  70. * 申请分销商
  71. * @throws Exception
  72. */
  73. public function applicationBusinessman()
  74. {
  75. $data = self::commonFieldFilter();
  76. $modelResult = $this->objMCommissionBusinessman->addBusinessman($data);
  77. if(!$modelResult->isSuccess()){
  78. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  79. }
  80. parent::sendOutput($modelResult->getData());
  81. }
  82. /**
  83. * 添加上下级关系
  84. * @throws Exception
  85. */
  86. public function relationshipBusinessman()
  87. {
  88. $params = $this->request->getRawJson();
  89. if(empty($params)){
  90. parent::sendOutput('参数为空', ErrorCode::$paramError);
  91. }
  92. $data = [
  93. 'businessmanId' => getArrayItem($params, 'businessmanId'),
  94. 'source' => getArrayItem($params, 'source'),
  95. ];
  96. //新分销合伙人添加下级
  97. if(!empty($data['businessmanId']) && !empty($this->customerData["id"])){
  98. $this->partnerTool->setPushCustomer($data['businessmanId'], $this->customerData["id"]);
  99. }
  100. foreach($data as $key => $value){
  101. if(empty($value) && $value !== 0){
  102. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  103. }
  104. }
  105. $modelResult = $this->objMCommissionBusinessman->relationshipBusinessman($data);
  106. if(!$modelResult->isSuccess()){
  107. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  108. }
  109. parent::sendOutput($modelResult->getData());
  110. }
  111. /**
  112. * 修改分销商
  113. * @throws Exception
  114. */
  115. public function updateBusinessman()
  116. {
  117. $id = $this->request->param('request_id');
  118. if(empty($id)){
  119. parent::sendOutput('参数为空', ErrorCode::$paramError);
  120. }
  121. $data = self::commonFieldFilter();
  122. $modelResult = $this->objMCommissionBusinessman->updateBusinessman($data, ['id' => $id]);
  123. if(!$modelResult->isSuccess()){
  124. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  125. }
  126. parent::sendOutput($modelResult->getData());
  127. }
  128. /**
  129. * 分销商详情
  130. */
  131. public function getInfoBusinessman()
  132. {
  133. $where['userCenterId'] = $this->onlineUserId;
  134. $modelResult = $this->objMCommissionBusinessman->getInfoBusinessman($where);
  135. if(!$modelResult->isSuccess()){
  136. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  137. }
  138. parent::sendOutput($modelResult->getData());
  139. }
  140. /**
  141. * 查询分销商的所有下级
  142. * @throws Exception
  143. */
  144. public function getAllSub()
  145. {
  146. $params = $this->request->getRawJson();
  147. if(empty($params)){
  148. parent::sendOutput('参数为空', ErrorCode::$paramError);
  149. }
  150. $data = [
  151. 'id' => isset($params['id']) ? $params['id'] : '',
  152. 'level' => isset($params['level']) ? $params['level'] : '',
  153. 'page' => isset($params['page']) ? $params['page'] : '',
  154. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : '',
  155. ];
  156. foreach($data as $key => $value){
  157. if(empty($value) && $value !== 0){
  158. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  159. }
  160. }
  161. $pageParams = pageToOffset($params['page'],$params['pageSize']);
  162. $data['limit'] = $pageParams['limit'];
  163. $data['offset'] = $pageParams['offset'];
  164. $modelResult = $this->objMCommissionBusinessman->getAllSub($data);
  165. if(!$modelResult->isSuccess()){
  166. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  167. }
  168. $returnData = $modelResult->getData();
  169. $pageData = [
  170. 'pageIndex' => $params['page'],
  171. 'pageSize' => $params['pageSize'],
  172. 'pageTotal' => $returnData['total'],
  173. 'subTotal' => $returnData['subTotal'],
  174. 'businessmanTotal' => $returnData['businessmanTotal'],
  175. 'subBusinessmanTotal' => $returnData['subBusinessmanTotal'],
  176. ];
  177. parent::sendOutput($returnData['data'], 0, $pageData);
  178. }
  179. /**
  180. * 排行榜
  181. */
  182. public function commissionTop()
  183. {
  184. $modelResult = $this->objMCommissionBusinessman->statisticsCommissionThree();
  185. if(!$modelResult->isSuccess()){
  186. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  187. }
  188. parent::sendOutput($modelResult->getData());
  189. }
  190. /**
  191. * 等级说明
  192. */
  193. public function getAllGrade()
  194. {
  195. $modelResult = $this->objMCommissionBusinessman->getBusinessmanGradeInfo();
  196. if(!$modelResult->isSuccess()){
  197. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  198. }
  199. parent::sendOutput($modelResult->getData());
  200. }
  201. /**
  202. * Doc: (des="分销中心订单列表")
  203. * User: XMing
  204. * Date: 2020/7/30
  205. * Time: 10:47 上午
  206. * @throws Exception
  207. */
  208. public function getCommissionOrder()
  209. {
  210. $params = $this->request->getRawJson();
  211. if(empty($params)){
  212. parent::sendOutput('参数为空', ErrorCode::$paramError);
  213. }
  214. $pageParams = pageToOffset($params['page'] ? $params['page'] : 1, $params['pageSize'] ? $params['pageSize'] : 10);
  215. $params['limit'] = $pageParams['limit'];
  216. $params['offset'] = $pageParams['offset'];
  217. $modelResult = $this->objMCommissionOrder->getCommissionOrder($params);
  218. if(!$modelResult->isSuccess()){
  219. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  220. }
  221. $returnData = $modelResult->getData();
  222. $pageData = [
  223. 'pageIndex' => $params['page'],
  224. 'pageSize' => $params['pageSize'],
  225. 'pageTotal' => $returnData['total'],
  226. ];
  227. parent::sendOutput($returnData['data'], 0, $pageData);
  228. }
  229. /**
  230. * Doc: (des="分销订单详情")
  231. * User: XMing
  232. * Date: 2020/7/30
  233. * Time: 4:06 下午
  234. * @throws Exception
  235. */
  236. public function getCommissionOrderInfo()
  237. {
  238. $id = $this->request->param('request_id');
  239. if(empty($id)){
  240. parent::sendOutput('参数为空', ErrorCode::$paramError);
  241. }
  242. $modelResult = $this->objMCommissionOrder->getCommissionOrderInfo($id);
  243. if(!$modelResult->isSuccess()){
  244. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  245. }
  246. parent::sendOutput($modelResult->getData());
  247. }
  248. /**
  249. * 修改直系上级关系
  250. * @throws Exception
  251. * 客户id,上级id
  252. */
  253. public function editRelationship()
  254. {
  255. $params = $this->request->getRawJson();
  256. if(empty($params['id']) || empty($params['superiorId']) ){
  257. parent::sendOutput('分销商参数错误', ErrorCode::$paramError);
  258. }
  259. $result = $this->objMCommissionBusinessman->editRelationship($params);
  260. if(!$result->isSuccess()){
  261. parent::sendOutput($result->getData(), $result->getErrorCode());
  262. }
  263. parent::sendOutput($result->getData());
  264. }
  265. }