Agents.Class.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <?php
  2. /**
  3. * 代理商
  4. * Created by PhpStorm.
  5. * User: user
  6. * Date: 2021/6/24
  7. * Time: 12:00
  8. */
  9. namespace JinDouYun\Controller\Agent;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\StatusCode;
  12. use JinDouYun\Model\Agent\MAgents;
  13. use JinDouYun\Model\Manage\MEnterprise;
  14. use JinDouYun\Model\Manage\MWxTemplate;
  15. use JinDouYun\Controller\BaseController;
  16. use JinDouYun\Model\UserCenter\MUserCenterRegister;
  17. class Agents extends BaseController
  18. {
  19. public $objMAgents;
  20. public function __construct($isCheckAcl = true, $isMustLogin = true)
  21. {
  22. parent::__construct($isCheckAcl, $isMustLogin);
  23. $this->objMAgents = new MAgents();
  24. }
  25. /**
  26. * 添加,编辑接收公共字段
  27. *
  28. * @return array
  29. */
  30. public function commonFieldFilter()
  31. {
  32. $params = $this->request->getRawJson();
  33. if (empty($params)) {
  34. $this->sendOutput('参数为空', ErrorCode::$paramError);
  35. }
  36. $AgentFieldData = [
  37. 'workName' => isset($params['workName']) ? $params['workName'] : '',//公司名称
  38. 'contact' => isset($params['contact']) ? $params['contact'] : '',//联系人
  39. 'address' => isset($params['address']) ? $params['address'] : '',//公司地址
  40. 'initiateStatus' => isset($params['initiateStatus']) ? $params['initiateStatus'] : '',//启用状态(0禁用 1启用)
  41. ];
  42. //判断必传
  43. foreach ($AgentFieldData as $key => $value) {
  44. if (empty($value) && $value !== 0) {
  45. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  46. }
  47. }
  48. $AgentFieldData['contact'] = json_encode($AgentFieldData['contact']);//联系人存json
  49. return $AgentFieldData;
  50. }
  51. /**
  52. * 添加代理商数据
  53. */
  54. public function addAgent()
  55. {
  56. $agentData = $this->commonFieldFilter();//接收公共字段
  57. $result = $this->objMAgents->addAgent($agentData);
  58. if ($result->isSuccess()) {
  59. parent::sendOutput($result->getData());
  60. }
  61. parent::sendOutput($result->getData(), $result->getErrorCode());
  62. }
  63. /**
  64. * 编辑代理商数据
  65. */
  66. public function editAgent()
  67. {
  68. $id = $this->request->param('id');
  69. if (empty($id)) {
  70. $this->sendOutput('参数错误', ErrorCode::$paramError);
  71. }
  72. $agentData = $this->commonFieldFilter();//接收公共字段
  73. $agentData['id'] = $id;
  74. $result = $this->objMAgents->editAgent($agentData);
  75. if ($result->isSuccess()) {
  76. parent::sendOutput($result->getData());
  77. }
  78. parent::sendOutput($result->getData(), $result->getErrorCode());
  79. }
  80. /**
  81. * 删除代理商数据
  82. */
  83. public function deleteAgent()
  84. {
  85. $id = $this->request->param('id');
  86. if(empty($id)){
  87. parent::sendOutput('id为空', ErrorCode::$paramError);
  88. }
  89. $result = $this->objMAgents->deleteAgent($id);//软删除
  90. if ($result->isSuccess()) {
  91. parent::sendOutput($result->getData());
  92. } else {
  93. parent::sendOutput($result->getData(), $result->getErrorCode());
  94. }
  95. }
  96. /**
  97. * 查询代理商
  98. */
  99. public function getAllAgent()
  100. {
  101. $page = $this->request->param('page') ?: 1;
  102. $pageSize = $this->request->param('pageSize') ?: 10;
  103. $offset = ($page - 1) * $pageSize;
  104. $selectParams = [
  105. 'limit' => $pageSize,
  106. 'offset' => $offset,
  107. ];
  108. $result = $this->objMAgents->getAllAgent($selectParams);
  109. if ($result->isSuccess()) {
  110. $returnData = $result->getData();
  111. $pageData = [
  112. 'pageIndex' => $page,
  113. 'pageSize' => $pageSize,
  114. 'pageTotal' => $returnData['total'],
  115. ];
  116. parent::sendOutput($returnData['data'], 0, $pageData);
  117. }
  118. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  119. }
  120. /**
  121. * oem代理商信息设置
  122. */
  123. public function oemSystemSet()
  124. {
  125. $params = $this->request->getRawJson();
  126. if( empty($params['setData']) or empty($params['type'])){
  127. $this->sendOutput('参数为空', ErrorCode::$paramError );
  128. }
  129. $result = $this->objMAgents->oemSystemSet($params,$this->onlineEnterpriseId);
  130. if ($result->isSuccess()) {
  131. parent::sendOutput($result->getData());
  132. }
  133. parent::sendOutput($result->getData(), $result->getErrorCode());
  134. }
  135. /**
  136. * 获取所有企业列表
  137. * @throws \Exception
  138. */
  139. public function getAllEnterprise()
  140. {
  141. $page = $this->request->param('page') ?: 1;
  142. $pageSize = $this->request->param('pageSize') ?: 10;
  143. $offset = ($page - 1) * $pageSize;
  144. $selectParams = [
  145. 'oemId' =>$this->onlineEnterpriseId,
  146. 'limit' => $pageSize,
  147. 'offset' => $offset,
  148. ];
  149. $objMEnterprise = new MEnterprise();
  150. $result = $objMEnterprise->getAllEnterprise($selectParams);
  151. if ($result->isSuccess()) {
  152. $returnData = $result->getData();
  153. $pageData = [
  154. 'pageIndex' => $page,
  155. 'pageSize' => $pageSize,
  156. 'pageTotal' => $returnData['total'],
  157. ];
  158. parent::sendOutput($returnData['enterpriseData'], 0, $pageData);
  159. } else {
  160. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  161. }
  162. }
  163. /**
  164. * 根据企业id获取oem企业
  165. */
  166. public function getOemInfo()
  167. {
  168. $result = $this->objMAgents->getOemInfo(['enterpriseId'=>$this->onlineEnterpriseId]);
  169. if ($result->isSuccess()) {
  170. parent::sendOutput($result->getData()[0]);
  171. }
  172. parent::sendOutput($result->getData(), $result->getErrorCode());
  173. }
  174. /**
  175. * 用户中心添加 / oem用户注册
  176. * @throws \Exception
  177. */
  178. public function addOemUserCenter()
  179. {
  180. //接收参数
  181. $params = $this->request->getRawJson();
  182. //映射参数
  183. $UserCenterData = [
  184. "mobile" => isset($params['mobile']) ? $params['mobile'] : '',
  185. "password" => isset($params['password']) ? $params['password'] : '',
  186. ];
  187. //校验参数
  188. foreach ($UserCenterData as $key => $value) {
  189. if (empty($value) && $value !== 0) {
  190. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  191. }
  192. }
  193. //校验手机号格式
  194. $this->checkMobile($UserCenterData['mobile']);
  195. //格式化密码
  196. $UserCenterData['password'] = password_hash($UserCenterData['password'], PASSWORD_DEFAULT );
  197. //来源标识
  198. $UserCenterData['source'] = StatusCode::$delete;
  199. $UserCenterData['createTime'] = time();
  200. $UserCenterData['updateTime'] = time();
  201. $objMUserCenterRegister = new MUserCenterRegister();
  202. $result = $objMUserCenterRegister->addUserCenter($UserCenterData);
  203. if ($result->isSuccess()) {
  204. parent::sendOutput($result->getData());
  205. } else {
  206. parent::sendOutput($result->getData(), $result->getErrorCode());
  207. }
  208. }
  209. /**
  210. * oem企业微信模版列表
  211. * @throws \Exception
  212. */
  213. public function getOemWxTemplateAll()
  214. {
  215. $params = $this->request->getRawJson();
  216. $pageParams = pageToOffset(isset($params['page']) ? $params['page'] : 1, isset($params['pageSize']) ? $params['pageSize'] : 10);
  217. $selectParams['limit'] = $pageParams['limit'];
  218. $selectParams['offset'] = $pageParams['offset'];
  219. $selectParams['oemId'] = $this->onlineEnterpriseId;
  220. $objMWxTemplate = new MWxTemplate();
  221. $result = $objMWxTemplate->getAll($selectParams);
  222. if ($result->isSuccess()) {
  223. $returnData = $result->getData();
  224. $pageData = [
  225. 'pageIndex' => isset($params['page']) ? $params['page'] : 1,
  226. 'pageSize' => isset($params['pageSize']) ? $params['pageSize'] : 10,
  227. 'pageTotal' => $returnData['total'],
  228. ];
  229. parent::sendOutput($returnData['data'], 0, $pageData);
  230. }
  231. parent::sendOutput($result->getData(), $result->getErrorCode());
  232. }
  233. /**
  234. * 查询oem套餐
  235. */
  236. public function getAllMeal()
  237. {
  238. $result = $this->objMAgents->getAllMeal();
  239. if ($result->isSuccess()) {
  240. parent::sendOutput($result->getData());
  241. }
  242. parent::sendOutput($result->getData(), ErrorCode::$dberror);
  243. }
  244. /**
  245. * oem续费
  246. */
  247. public function renew()
  248. {
  249. $params = $this->request->getRawJson();
  250. if (empty($params)) {
  251. $this->sendOutput('参数为空', ErrorCode::$paramError);
  252. }
  253. $details = [
  254. 'enterpriseId' => getArrayItem($params,'enterpriseId',0),
  255. 'enterpriseName' => getArrayItem($params,'enterpriseName',''),
  256. 'mobile' => getArrayItem($params,'mobile',0),
  257. 'money' => getArrayItem($params,'money',0),
  258. 'mealId' => getArrayItem($params,'mealId',0),
  259. ];
  260. foreach ($details as $key => $value) {
  261. if (empty($value) && $value !== 0) {
  262. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  263. }
  264. }
  265. $result = $this->objMAgents->renew($params);
  266. if ($result->isSuccess()) {
  267. parent::sendOutput($result->getData());
  268. } else {
  269. parent::sendOutput($result->getData(), $result->getErrorCode());
  270. }
  271. }
  272. /**
  273. * 消费记录列表
  274. */
  275. public function getAllRenew()
  276. {
  277. $params = $this->request->getRawJson();
  278. if (empty($params)) {
  279. $this->sendOutput('参数为空', ErrorCode::$paramError);
  280. }
  281. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  282. $params['limit'] = $pageParams['limit'];
  283. $params['offset'] = $pageParams['offset'];
  284. $params['enterpriseId'] = getArrayItem($params,'enterpriseId',0);
  285. $params['mobile'] = getArrayItem($params,'mobile',"");
  286. $params['mealId'] = getArrayItem($params,'mealId',0);
  287. $returnData = $this->objMAgents->getAllRenew($params);
  288. if ($returnData->isSuccess()) {
  289. $returnData = $returnData->getData();
  290. $pageData = [
  291. 'pageIndex' => $params['page'],
  292. 'pageSize' => $params['pageSize'],
  293. 'pageTotal' => $returnData['total'],
  294. ];
  295. parent::sendOutput($returnData['data'], 0, $pageData);
  296. } else {
  297. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  298. }
  299. }
  300. }