ApiCustomer.Class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <?php
  2. /**
  3. * 获取当前登录的客户信息
  4. * Created by PhpStorm.
  5. * User: wxj
  6. * Date: 2019/11/20
  7. * Time: 19:24
  8. */
  9. namespace JinDouYun\Controller\Customer;
  10. use Exception;
  11. use Mall\Framework\Core\ErrorCode;
  12. use Mall\Framework\Core\StatusCode;
  13. use Jindouyun\Cache\CustomerCache;
  14. use JinDouYun\Controller\BaseController;
  15. use JinDouYun\Model\Customer\MCustomer;
  16. use JinDouYun\Model\System\MCustomerSource;
  17. use JinDouYun\Model\Goods\MGoodsCollect;
  18. use JinDouYun\Model\Customer\MCustomerDemand;
  19. use JinDouYun\Model\Customer\MCustomerVisitsLog;
  20. use JinDouYun\Model\Customer\MMemberBalanceDetail;
  21. use JinDouYun\Model\Customer\MReflectDetail;
  22. use JinDouYun\Model\Finance\MCustomerBalanceDetail;
  23. use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
  24. class ApiCustomer extends BaseController
  25. {
  26. private $objMCustomer;
  27. private $objMCustomerSource;
  28. private $objMGoodsCollect;
  29. private $objMCustomerDemand;
  30. private $objMCustomerVisitsLog;
  31. private $objMMemberBalanceDetail;
  32. private $objMReflectDetail;
  33. private $objMCustomerBalanceDetail;
  34. public function __construct($isCheckAcl = false, $isMustLogin = true, $checkToken = true)
  35. {
  36. parent::__construct($isCheckAcl, $isMustLogin, $checkToken);
  37. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  38. $this->objMCustomerSource = new MCustomerSource($this->onlineEnterpriseId);
  39. $this->objMGoodsCollect = new MGoodsCollect($this->onlineEnterpriseId, $this->onlineUserId);
  40. $this->objMCustomerDemand = new MCustomerDemand($this->onlineEnterpriseId, $this->onlineUserId);
  41. $this->objMCustomerVisitsLog = new MCustomerVisitsLog($this->onlineEnterpriseId, $this->onlineUserId);
  42. $this->objMMemberBalanceDetail = new MMemberBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
  43. $this->objMReflectDetail = new MReflectDetail($this->onlineEnterpriseId, $this->onlineUserId);
  44. $this->objMCustomerBalanceDetail = new MCustomerBalanceDetail($this->onlineEnterpriseId, $this->onlineUserId);
  45. }
  46. /**
  47. * 添加和编辑客户管理公共字段处理方法
  48. *
  49. * @return array
  50. */
  51. public function commonFieldFilter()
  52. {
  53. $params = $this->request->getRawJson();
  54. if (empty($params)) {
  55. $this->sendOutput('参数为空', ErrorCode::$paramError);
  56. }
  57. $customerData = [
  58. 'name' => isset($params['name']) ? $params['name'] : '',
  59. 'contact' => isset($params['contact']) ? $params['contact'] : '',
  60. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  61. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  62. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  63. ];
  64. foreach ($customerData as $key => $value) {
  65. if (empty($value) && $value !== 0) {
  66. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  67. }
  68. }
  69. $customerData['type'] = isset($params['type']) ? $params['type'] : '';
  70. $customerData['recommenderType'] = isset($params['recommenderType']) ? $params['recommenderType'] : '';
  71. $customerData['recommenderId'] = isset($params['recommenderId']) ? $params['recommenderId'] : '';
  72. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : 0;//经度
  73. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : 0;//纬度
  74. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';
  75. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  76. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  77. $customerData['extend'] = isset($params['extend']) ? json_encode($params['extend']) : '';
  78. $customerData['address'] = getArrayItem($params, 'address', '');
  79. $customerData['updateTime'] = time();
  80. return $customerData;
  81. }
  82. /**
  83. * 修改当前客户信息
  84. */
  85. public function editCustomerInfo()
  86. {
  87. $customerData = $this->commonFieldFilter();
  88. $customerData['userCenterId'] = $this->onlineUserId;
  89. $result = $this->objMCustomer->editCustomerInfo($customerData);
  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 getCustomerInfo()
  100. {
  101. $customerData = $this->objMCustomer->getCustomerInfoByUserCenterId($this->onlineUserId, true);
  102. if ($customerData->isSuccess()) {
  103. $customerInfo = $customerData->getData();
  104. $this->sendOutput($customerInfo);
  105. } else {
  106. $this->sendOutput($customerData->getData(), ErrorCode::$contentNotExists);
  107. }
  108. }
  109. /**
  110. * 完善资料获取客户类型
  111. */
  112. public function getCustomerSourceList()
  113. {
  114. $result = $this->objMCustomerSource->getCustomerSourceList();
  115. if ($result->isSuccess()) {
  116. $returnData = $result->getData();
  117. parent::sendOutput($returnData);
  118. } else {
  119. parent::sendOutput($result->getData(), $result->getErrorCode());
  120. }
  121. }
  122. /**
  123. * 收藏商品
  124. * @throws Exception
  125. */
  126. public function collect()
  127. {
  128. $goodsId = $this->request->param('request_id');
  129. if (!$goodsId) {
  130. $this->sendOutput('参数错误', ErrorCode::$paramError);
  131. }
  132. $result = $this->objMGoodsCollect->addGoodsCollect($goodsId);
  133. if ($result->isSuccess()) {
  134. $this->sendOutput($result->getData());
  135. }
  136. $this->sendOutput($result->getData(), $result->getErrorCode());
  137. }
  138. /**
  139. * 充值余额
  140. * @throws Exception
  141. */
  142. public function rechargeBalance()
  143. {
  144. $params = $this->request->getRawJson();
  145. $data['money'] = isset($params['money']) ? $params['money'] : '';
  146. foreach ($data as $key => $value) {
  147. if (empty($value)) {
  148. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  149. }
  150. }
  151. $data['userCenterId'] = $this->onlineUserId;
  152. $data['id'] = $this->request->get_onlineip();
  153. $result = $this->objMCustomer->rechargeBalance($data);
  154. if (!$result->isSuccess()) {
  155. parent::sendOutput($result->getData(), $result->getErrorCode());
  156. }
  157. parent::sendOutput($result->getData());
  158. }
  159. /**
  160. * 充值记录列表
  161. */
  162. public function getAllRechargeBalance()
  163. {
  164. $params = $this->request->getRawJson();
  165. if (empty($params)) {
  166. $this->sendOutput('参数为空', ErrorCode::$paramError);
  167. }
  168. $selectParams['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  169. foreach ($selectParams as $key => $value) {
  170. if (empty($value)) {
  171. parent::sendOutput($key . '参数错误', ErrorCode::$paramError);
  172. }
  173. }
  174. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  175. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  176. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  177. $selectParams['limit'] = $pageParams['limit'];
  178. $selectParams['offset'] = $pageParams['offset'];
  179. $selectParams['userCenterId'] = $this->onlineUserId;
  180. $modelResult = $this->objMCustomer->getAllRechargeBalance($selectParams);
  181. if (!$modelResult->isSuccess()) {
  182. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  183. }
  184. $returnData = $modelResult->getData();
  185. $pageData = [
  186. 'pageIndex' => $params['page'],
  187. 'pageSize' => $params['pageSize'],
  188. 'pageTotal' => $returnData['total'],
  189. ];
  190. parent::sendOutput($returnData['data'], 0, $pageData);
  191. }
  192. /**
  193. * 添加客户需求
  194. */
  195. public function addCustomerdemand()
  196. {
  197. $params = $this->request->getRawJson();
  198. if (empty($params)) {
  199. $this->sendOutput('参数为空', ErrorCode::$paramError);
  200. }
  201. $demandData = [
  202. 'enterpriseId' => $this->onlineEnterpriseId,
  203. 'customerId' => getArrayItem($params, 'customerId'),
  204. 'demand' => getArrayItem($params, 'demand'),
  205. ];
  206. $demandData['updateTime'] = time();
  207. $result = $this->objMCustomerDemand->addCustomerdemand($demandData);
  208. if ($result->isSuccess()) {
  209. parent::sendOutput($result->getData());
  210. } else {
  211. parent::sendOutput($result->getData(), $result->getErrorCode());
  212. }
  213. }
  214. /**
  215. * 添加客户访问记录
  216. */
  217. public function addCustomerVisitsLog()
  218. {
  219. $params = $this->request->getRawJson();
  220. if (empty($params)) {
  221. $this->sendOutput('参数为空', ErrorCode::$paramError);
  222. }
  223. $visitsLogData = [
  224. 'usercenterid' => getArrayItem($params, 'usercenterid'),
  225. 'customerid' => getArrayItem($params, 'customerid'),
  226. 'shopid' => getArrayItem($params, 'shopid'),
  227. 'goodsid' => getArrayItem($params, 'goodsid'),
  228. ];
  229. $visitsLogData['updateTime'] = time();
  230. $result = $this->objMCustomerVisitsLog->addCustomerVisitsLog($visitsLogData);
  231. if ($result->isSuccess()) {
  232. parent::sendOutput($result->getData());
  233. } else {
  234. parent::sendOutput($result->getData(), $result->getErrorCode());
  235. }
  236. }
  237. /**
  238. * 添加余额支付密码
  239. */
  240. public function addpayPassword()
  241. {
  242. $params = $this->request->getRawJson();
  243. if (empty($params)) {
  244. $this->sendOutput('参数为空', ErrorCode::$paramError);
  245. }
  246. $payPasswordData = [
  247. 'enterpriseId' => $this->onlineEnterpriseId,
  248. 'id' => getArrayItem($params, 'id'),
  249. 'payPassword' => getArrayItem($params, 'payPassword'),
  250. ];
  251. foreach ($payPasswordData as $key => $value) {
  252. if (empty($value)) {
  253. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  254. }
  255. }
  256. $payPasswordData['updateTime'] = time();
  257. //密码格式化;
  258. $payPasswordData['payPassword'] = password_hash($payPasswordData['payPassword'], PASSWORD_DEFAULT);
  259. $result = $this->objMCustomer->addpayPassword($payPasswordData);
  260. if ($result->isSuccess()) {
  261. parent::sendOutput($result->getData());
  262. } else {
  263. parent::sendOutput($result->getData(), $result->getErrorCode());
  264. }
  265. }
  266. /**
  267. * 修改余额支付密码
  268. */
  269. public function updatePayPassword()
  270. {
  271. $params = $this->request->getRawJson();
  272. if (!$params) {
  273. $this->sendOutput('参数错误', ErrorCode::$paramError);
  274. }
  275. $updatePayPasswordData = [
  276. 'enterpriseId' => $this->onlineEnterpriseId,
  277. 'id' => getArrayItem($params, 'id'),
  278. 'payPassword' => trim(getArrayItem($params, 'payPassword')),
  279. ];
  280. foreach ($updatePayPasswordData as $key => $value) {
  281. if (empty($value)) {
  282. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  283. }
  284. }
  285. $updatePayPasswordData['updateTime'] = time();
  286. $updatePayPasswordData['payPassword'] = password_hash($updatePayPasswordData['payPassword'], PASSWORD_DEFAULT);
  287. $result = $this->objMCustomer->updatePayPassword($updatePayPasswordData);
  288. if ($result->isSuccess()) {
  289. parent::sendOutput($result->getData());
  290. } else {
  291. parent::sendOutput($result->getData(), $result->getErrorCode());
  292. }
  293. }
  294. /**
  295. * 校验余额支付密码
  296. */
  297. public function checkPayPassword()
  298. {
  299. $params = $this->request->getRawJson();
  300. if (!$params) {
  301. $this->sendOutput('参数错误', ErrorCode::$paramError);
  302. }
  303. $checkPayPasswordData = [
  304. 'enterpriseId' => $this->onlineEnterpriseId,
  305. 'id' => getArrayItem($params, 'id'),
  306. 'payPassword' => trim(getArrayItem($params, 'payPassword')),
  307. ];
  308. foreach ($checkPayPasswordData as $key => $value) {
  309. if (empty($value)) {
  310. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  311. }
  312. }
  313. $result = $this->objMCustomer->checkPayPassword($checkPayPasswordData);
  314. if ($result->isSuccess()) {
  315. parent::sendOutput($result->getData());
  316. } else {
  317. parent::sendOutput($result->getData(), $result->getErrorCode());
  318. }
  319. }
  320. /**
  321. * 获取所有的明细
  322. */
  323. public function getAllMemberBalanceDetail()
  324. {
  325. $params = $this->request->getRawJson();
  326. if (empty($params)) {
  327. $this->sendOutput('参数为空', ErrorCode::$paramError);
  328. }
  329. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  330. $params['limit'] = $pageParams['limit'];
  331. $params['offset'] = $pageParams['offset'];
  332. $params['userCenterId'] = $this->onlineUserId;
  333. $params['customerId'] = getArrayItem($params, 'customerId', '');
  334. $returnData = $this->objMMemberBalanceDetail->getAllMemberBalanceDetail($params);
  335. if ($returnData->isSuccess()) {
  336. $returnData = $returnData->getData();
  337. $pageData = [
  338. 'pageIndex' => $params['page'],
  339. 'pageSize' => $params['pageSize'],
  340. 'pageTotal' => $returnData['total'],
  341. ];
  342. parent::sendOutput($returnData['data'], 0, $pageData);
  343. } else {
  344. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  345. }
  346. }
  347. /**
  348. * 申请提现
  349. */
  350. public function addReflectDetail()
  351. {
  352. $params = $this->request->getRawJson();
  353. if (empty($params)) {
  354. $this->sendOutput('参数为空', ErrorCode::$paramError);
  355. }
  356. $ReflectDetailDate = [
  357. 'customerId' => getArrayItem($params, 'customerId', ''),
  358. 'userCenterId' => $this->onlineUserId,
  359. 'reflectType' => getArrayItem($params, 'reflectType', ''),
  360. 'money' => getArrayItem($params, 'money', ''),
  361. 'reflectInfo' => getArrayItem($params, 'reflectInfo', []),
  362. 'reflectStatus' => getArrayItem($params, 'reflectStatus', 4),
  363. 'auditStatus' => getArrayItem($params, 'auditStatus', StatusCode::$auditStatus['auditing']),
  364. ];
  365. foreach ($ReflectDetailDate as $key => $value) {
  366. if (empty($value) && $value !== 0) {
  367. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  368. }
  369. }
  370. $ReflectDetailDate['reflectInfo'] = json_encode($ReflectDetailDate['reflectInfo']);
  371. $ReflectDetailDate['remark'] = getArrayItem($params, 'remark', '');
  372. $ReflectDetailDate['createTime'] = time();
  373. $result = $this->objMReflectDetail->addReflectDetail($ReflectDetailDate);
  374. if ($result->isSuccess()) {
  375. parent::sendOutput($result->getData());
  376. } else {
  377. parent::sendOutput($result->getData(), $result->getErrorCode());
  378. }
  379. }
  380. /**
  381. * 所有提现记录
  382. */
  383. public function getAllReflectDetail()
  384. {
  385. $params = $this->request->getRawJson();
  386. if (empty($params)) {
  387. $this->sendOutput('参数为空', ErrorCode::$paramError);
  388. }
  389. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  390. $params['limit'] = $pageParams['limit'];
  391. $params['offset'] = $pageParams['offset'];
  392. $params['start'] = getArrayItem($params, 'start', "");
  393. $params['end'] = getArrayItem($params, 'end', "");
  394. $params['customerId'] = getArrayItem($params, 'customerId', '');
  395. $returnData = $this->objMReflectDetail->getAllReflectDetail($params);
  396. if ($returnData->isSuccess()) {
  397. $returnData = $returnData->getData();
  398. $pageData = [
  399. 'pageIndex' => $params['page'],
  400. 'pageSize' => $params['pageSize'],
  401. 'pageTotal' => $returnData['total'],
  402. ];
  403. parent::sendOutput($returnData['data'], 0, $pageData);
  404. } else {
  405. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  406. }
  407. }
  408. /**
  409. * 积分流水
  410. */
  411. public function getAllCustomerIntegralDesc()
  412. {
  413. $params = $this->request->getRawJson();
  414. $page = isset($params['page']) ? $params['page'] : 1;
  415. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  416. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  417. $data['limit'] = $pageParams['limit'];
  418. $data['offset'] = $pageParams['offset'];
  419. $data['customerId'] = $params['customerId'];
  420. if (empty($params['customerId'])) {
  421. parent::sendOutput('customerId参数为空', ErrorCode::$paramError);
  422. }
  423. if (isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])) {
  424. $data['createTime'] = [
  425. 'star' => $params['star'],
  426. 'end' => $params['end']
  427. ];
  428. }
  429. $modelResult = $this->objMCustomer->getAllCustomerIntegralDesc($data);
  430. if (!$modelResult->isSuccess()) {
  431. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  432. }
  433. $returnData = $modelResult->getData();
  434. $pageData = [
  435. 'pageIndex' => $page,
  436. 'pageSize' => $pageSize,
  437. 'pageTotal' => $returnData['total'],
  438. ];
  439. parent::sendOutput($returnData['data'], 0, $pageData);
  440. }
  441. /**
  442. * 小程序充值
  443. */
  444. public function rechargeMemberBalance()
  445. {
  446. $params = $this->request->getRawJson();
  447. if (empty($params)) {
  448. $this->sendOutput('参数为空', ErrorCode::$paramError);
  449. }
  450. //记录流水
  451. $memberBalanceDetailData = [
  452. 'customerId' => $params['customerId'],
  453. 'type' => StatusCode::$standard,
  454. 'userCenterId' => $this->onlineUserId,
  455. 'money' => $params['money'],
  456. 'purpose' => '充值',
  457. 'orderIds' => '',
  458. 'remark' => '充值' . $params['money'],
  459. 'financeType' => '会员余额充值',
  460. ];
  461. foreach ($memberBalanceDetailData as $k => $v) {
  462. if (in_array($k, ['customerId', 'money', 'purpose']) && empty($v)) {
  463. $this->sendOutput('请输入' . $k, ErrorCode::$paramError);
  464. }
  465. }
  466. $result = $this->objMMemberBalanceDetail->addMemberBalanceDetail($memberBalanceDetailData);
  467. if ($result->isSuccess()) {
  468. parent::sendOutput($result->getData());
  469. } else {
  470. parent::sendOutput($result->getData(), $result->getErrorCode());
  471. }
  472. }
  473. /**
  474. * 小程序客户余额明细列表
  475. */
  476. public function getAllCustomerBalanceDetail()
  477. {
  478. $params = $this->request->getRawJson();
  479. if (empty($params)) {
  480. $this->sendOutput('参数为空', ErrorCode::$paramError);
  481. }
  482. $selectParams = [
  483. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  484. ];
  485. foreach ($selectParams as $key => $value) {
  486. if (empty($value) && $value !== 0) {
  487. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  488. }
  489. }
  490. $selectParams['start'] = !empty($params['start']) ? $params['start'] : 0;
  491. $selectParams['end'] = !empty($params['end']) ? strtotime(date('Y-m-d', $params['end']) . '23:59:59') : time();
  492. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  493. $selectParams['limit'] = $pageParams['limit'];
  494. $selectParams['offset'] = $pageParams['offset'];
  495. $result = $this->objMCustomerBalanceDetail->getAllCustomerBalanceDetail($selectParams);
  496. if ($result->isSuccess()) {
  497. $returnData = $result->getData();
  498. $pageData = [
  499. 'pageIndex' => $params['page'],
  500. 'pageSize' => $params['pageSize'],
  501. 'pageTotal' => $returnData['total'],
  502. 'openingBalance' => $returnData['openingBalance'],
  503. 'endingBalance' => $returnData['endingBalance'],
  504. 'shouldReceiveTotal' => $returnData['shouldReceiveTotal'],
  505. 'actualReceiveTotal' => $returnData['actualReceiveTotal'],
  506. ];
  507. parent::sendOutput($returnData['data'], 0, $pageData);
  508. } else {
  509. parent::sendOutput($result->getData(), $result->getErrorCode());
  510. }
  511. }
  512. }