Customer.Class.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. <?php
  2. /**
  3. * 客户管理模块
  4. * Created by PhpStorm.
  5. * User: tpl
  6. * Date: 2019/10/30
  7. * Time: 13:54
  8. */
  9. namespace JinDouYun\Controller\Customer;
  10. use JinDouYun\Dao\Department\DDepartment;
  11. use JinDouYun\Dao\Department\DStaff;
  12. use JinDouYun\Dao\Shop\DShop;
  13. use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
  14. use JinDouYun\Dao\System\DCustomerSource;
  15. use Mall\Framework\Core\ErrorCode;
  16. use Mall\Framework\Core\StatusCode;
  17. use JinDouYun\Controller\BaseController;
  18. use Jindouyun\Cache\CustomerCache;
  19. use JinDouYun\Model\Customer\MCustomer;
  20. use JinDouYun\Model\Order\MOrder;
  21. use JinDouYun\Model\Customer\MReflectDetail;
  22. use JinDouYun\Model\Customer\MMemberBalanceDetail;
  23. class Customer extends BaseController
  24. {
  25. /**
  26. * @var MCustomer
  27. */
  28. private $objMReflectDetail;
  29. private $objMMemberBalanceDetail;
  30. private $objMCustomer;
  31. //private $objTempSaveCache;
  32. public function __construct($isCheckAcl = true, $isMustLogin = true)
  33. {
  34. parent::__construct($isCheckAcl, $isMustLogin);
  35. $this->objMCustomer = new MCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  36. $this->objMReflectDetail = new MReflectDetail($this->onlineEnterpriseId,$this->onlineUserId);
  37. $this->objMMemberBalanceDetail = new MMemberBalanceDetail($this->onlineEnterpriseId,$this->onlineUserId);
  38. //$this->objTempSaveCache = new TempSaveCache();
  39. }
  40. /**
  41. * 添加和编辑客户管理公共字段处理方法
  42. *
  43. * @return array
  44. */
  45. public function commonFieldFilter(){
  46. $params = $this->request->getRawJson();
  47. if( empty($params) ){
  48. $this->sendOutput('参数为空', ErrorCode::$paramError );
  49. }
  50. $customerData = [
  51. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//账号
  52. 'name' => isset($params['name']) ? $params['name'] : '',
  53. 'type' => isset($params['type']) ? $params['type'] : '',//客户类型
  54. ];
  55. //非暂存则验空
  56. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  57. foreach($customerData as $key => $value){
  58. if(empty($value) && $value !== 0){
  59. $this->sendOutput($key.'参数错误', ErrorCode::$paramError);
  60. }
  61. }
  62. }
  63. $customerData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;//启用状态
  64. $customerData['contact'] = isset($params['contact']) ? $params['contact'] : '';
  65. $customerData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  66. $customerData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  67. $customerData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  68. $customerData['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  69. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : '';
  70. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : '';
  71. $customerData['tempSave']= isset($params['tempSave']) ? $params['tempSave'] : false;
  72. $customerData['password'] = isset($params['password']) ? $params['password'] : '';//密码
  73. $customerData['address'] = isset($params['address']) ? $params['address'] : '';
  74. $customerData['managerMobile'] = isset($params['managerMobile']) ? $params['managerMobile'] : '';
  75. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';//客户头像
  76. // $customerData['sortingId'] = isset($params['sortingId']) ? $params['sortingId'] : '';
  77. $customerData['departmentId'] = isset($params['departmentId']) ? $params['departmentId'] : '';
  78. $customerData['salesManId'] = isset($params['salesManId']) ? $params['salesManId'] : '';
  79. $customerData['salesManCode'] = isset($params['salesManCode']) ? $params['salesManCode'] : '';
  80. $customerData['salesManName'] = isset($params['salesManName']) ? $params['salesManName'] : '';
  81. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  82. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  83. $customerData['deleteStatus']= StatusCode::$standard;
  84. $customerData['status']= isset($params['status']) ? $params['status'] : '';
  85. $customerData['area'] = isset($params['area']) ? $params['area'] : [];
  86. $customerData['shopName'] = isset($params['shopName']) ? $params['shopName'] : '';
  87. $customerData['reservoirId'] = isset($params['reservoirId']) ? $params['reservoirId'] : '';
  88. (isset($params['extend']) && !empty($params['extend'])) && $customerData['extend'] = json_encode($params['extend']);
  89. $customerData['memberBalance'] = getArrayItem($params, 'memberBalance','');
  90. $customerData['recommenderType'] = getArrayItem($params,'recommenderType','');
  91. $customerData['recommenderId'] =getArrayItem($params,'recommenderId','');
  92. $customerData['createTime'] = time();
  93. $customerData['updateTime'] = time();
  94. //联系人信息
  95. $customerData['contact'] = getArrayItem($params,'contact', []);
  96. return $customerData;
  97. }
  98. /**
  99. * 添加客户
  100. * @throws \Exception
  101. */
  102. public function addCustomer()
  103. {
  104. $customerData = $this->commonFieldFilter();
  105. if ($customerData['tempSave']) {
  106. //$this->objTempSaveCache->saveCustomer($this->onlineEnterpriseId, $this->onlineUserId, $customerData);
  107. parent::sendOutput('暂存成功');
  108. }
  109. unset($customerData['tempSave']);
  110. unset($customerData['area']);
  111. unset($customerData['shopName']);
  112. $result = $this->objMCustomer ->addCustomer($customerData);
  113. if($result->isSuccess()){
  114. //删除暂存数据
  115. //$this->objTempSaveCache->delCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  116. parent::sendOutput($result->getData());
  117. }else{
  118. parent::sendOutput($result->getData(), $result->getErrorCode());
  119. }
  120. }
  121. /**
  122. * 获取暂存信息
  123. */
  124. public function getTempData()
  125. {
  126. //$result = $this->objTempSaveCache->getCustomer($this->onlineEnterpriseId, $this->onlineUserId);
  127. $this->sendOutput('');
  128. }
  129. /**
  130. * 获取指定客户信息
  131. * @throws \Exception
  132. */
  133. public function getCustomerInfo()
  134. {
  135. $customerId = $this->request->param('request_id');
  136. if ( !$customerId ) {
  137. $this->sendOutput('参数错误', ErrorCode::$paramError );
  138. }
  139. // 直接从缓存层返回
  140. $objCustomerCache = new CustomerCache();
  141. $customerData = $objCustomerCache->getCustomerData($this->onlineEnterpriseId, $customerId);
  142. if( !empty($customerData) ){
  143. $this->sendOutput($customerData);
  144. }
  145. $result = $this->objMCustomer->getCustomerInfo($customerId);
  146. if($result->isSuccess()){
  147. $objCustomerCache->cacheCustomerData($this->onlineEnterpriseId, $customerId, $result->getData());
  148. $this->sendOutput($result->getData());
  149. }else{
  150. $this->sendOutput($result->getData(), $result->getErrorCode());
  151. }
  152. }
  153. /**
  154. * 编辑客户
  155. * @throws \Exception
  156. */
  157. public function editCustomer()
  158. {
  159. $customerId = $this->request->param('request_id');
  160. if(empty($customerId)){
  161. $this->sendOutput('参数错误', ErrorCode::$paramError);
  162. }
  163. $customerData = $this->commonFieldFilter();
  164. $customerData['id'] = $customerId;
  165. unset($customerData['createTime']);
  166. unset($customerData['status']);
  167. unset($customerData['tempSave']);
  168. unset($customerData['area']);
  169. unset($customerData['shopName']);
  170. $result = $this->objMCustomer->editCustomer($customerData);
  171. if($result->isSuccess()){
  172. parent::sendOutput($result->getData());
  173. }else{
  174. parent::sendOutput($result->getData(), $result->getErrorCode());
  175. }
  176. }
  177. /**
  178. * 后台批量分配部门及业务员
  179. */
  180. public function batchEditCustomer()
  181. {
  182. $params = $this->request->getRawJson();
  183. $data = [
  184. 'ids' => isset($params['ids']) ? $params['ids'] : [],
  185. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : 0,//部门id
  186. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : 0,//业务员id
  187. ];
  188. foreach ($data as $key => $val){
  189. if (empty($val)){
  190. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  191. }
  192. }
  193. $result = $this->objMCustomer->batchEditCustomer($data);
  194. if(!$result->isSuccess()){
  195. $objCustomerCache = new CustomerCache();
  196. foreach ($data['ids'] as $key => $value){
  197. $objCustomerCache->delCustomerData($this->onlineEnterpriseId, $value);
  198. }
  199. parent::sendOutput($result->getData(), $result->getErrorCode());
  200. }
  201. parent::sendOutput($result->getData());
  202. }
  203. /**
  204. * 删除客户
  205. * @throws \Exception
  206. */
  207. public function delCustomer()
  208. {
  209. $userCenterIds = $this->request->getRawJson();
  210. if(!$userCenterIds){
  211. $this->sendOutput('参数错误', ErrorCode::$paramError);
  212. }
  213. $result = $this->objMCustomer->delCustomer($userCenterIds);
  214. if($result->isSuccess()){
  215. parent::sendOutput($result->getData());
  216. }else{
  217. parent::sendOutput($result->getData(), $result->getErrorCode());
  218. }
  219. }
  220. /**
  221. * 客户启用和禁用
  222. * @throws \Exception
  223. */
  224. public function updateCustomerStatus()
  225. {
  226. $params = $this->request->getRawJson();
  227. if( empty($params['id']) && empty($params['enableStatus'])){
  228. $this->sendOutput('参数为空', ErrorCode::$paramError );
  229. }
  230. $result = $this->objMCustomer->updateCustomerStatus($params);
  231. if($result->isSuccess()){
  232. parent::sendOutput($result->getData());
  233. }else{
  234. parent::sendOutput($result->getData(), $result->getErrorCode());
  235. }
  236. }
  237. /**
  238. * 客户审核通过和审核拒绝
  239. * @throws \Exception
  240. */
  241. public function updateCustomerCheckStatus()
  242. {
  243. $params = $this->request->getRawJson();
  244. if( empty($params['id']) && empty($params['status'])){
  245. $this->sendOutput('参数为空', ErrorCode::$paramError );
  246. }
  247. if($params['status'] == StatusCode::$auditStatus['auditNotPass'] && !isset($params['reason'])) {
  248. $this->sendOutput('请输入审核拒绝的原因', ErrorCode::$paramError );
  249. }
  250. $params['reason'] = isset($params['reason']) ? $params['reason'] : '';
  251. $result = $this->objMCustomer->updateCustomerCheckStatus($params);
  252. if($result->isSuccess()){
  253. parent::sendOutput($result->getData());
  254. }else{
  255. parent::sendOutput($result->getData(), $result->getErrorCode());
  256. }
  257. }
  258. /**
  259. * 后台所有客户列表
  260. * @throws \Exception
  261. */
  262. public function getAllCustomer()
  263. {
  264. $params = $this->request->getRawJson();
  265. if( empty($params) ){
  266. $this->sendOutput('参数为空', ErrorCode::$paramError );
  267. }
  268. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  269. $condition = [
  270. 'status' => isset($params['status']) ? $params['status'] : 2,
  271. 'enableStatus' => getArrayItem($params, 'enableStatus', 0),
  272. 'keyword' => getArrayItem($params, 'keyword', ''),
  273. 'salesManId' => getArrayItem($params, 'salesManId', 0),
  274. 'shopId' => getArrayItem($params, 'shopId', 0),
  275. 'cityCode' => getArrayItem($params, 'cityCode', 0),
  276. 'districtCode' => getArrayItem($params, 'districtCode', 0),
  277. 'provinceCode' => getArrayItem($params, 'provinceCode', 0),
  278. 'offset' => $pageParams['offset'],
  279. 'limit' => $pageParams['limit'],
  280. ];
  281. $result = $this->objMCustomer->getAllCustomer($condition);
  282. if($result->isSuccess()){
  283. $returnData = $result->getData();
  284. $pageData = [
  285. 'pageIndex' => $params['page'],
  286. 'pageSize' => $params['pageSize'],
  287. 'pageTotal' => $returnData['total'],
  288. ];
  289. parent::sendOutput($returnData['data'], 0, $pageData);
  290. }else{
  291. parent::sendOutput($result->getData(), $result->getErrorCode());
  292. }
  293. }
  294. /**
  295. * 添加客户标签
  296. * @throws \Exception
  297. */
  298. public function addCustomerTag() {
  299. $params = $this->request->getRawJson();
  300. if( empty($params['id']) && empty($params['tag']) ){
  301. $this->sendOutput('参数为空', ErrorCode::$paramError );
  302. }
  303. $result = $this->objMCustomer->addCustomerTag($params);
  304. if($result->isSuccess()){
  305. parent::sendOutput($result->getData());
  306. }else{
  307. parent::sendOutput($result->getData(), $result->getErrorCode());
  308. }
  309. }
  310. /**
  311. * 删除客户标签
  312. * @throws \Exception
  313. */
  314. public function delCustomerTag() {
  315. $params = $this->request->getRawJson();
  316. if( empty($params['id']) && empty($params['tag']) ){
  317. $this->sendOutput('参数为空', ErrorCode::$paramError );
  318. }
  319. $result = $this->objMCustomer->delCustomerTag($params);
  320. if($result->isSuccess()){
  321. parent::sendOutput($result->getData());
  322. }else{
  323. parent::sendOutput($result->getData(), $result->getErrorCode());
  324. }
  325. }
  326. /**
  327. * 搜索
  328. */
  329. public function search() {
  330. $params = $this->request->getRawJson();
  331. if( empty($params) ){
  332. $this->sendOutput('参数为空', ErrorCode::$paramError );
  333. }
  334. $selectParams = [
  335. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  336. 'type' => isset($params['type']) ? $params['type'] : '',
  337. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  338. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  339. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  340. 'status' => isset($params['status']) ? $params['status'] : '',
  341. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  342. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  343. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : '',
  344. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
  345. 'start' => isset($params['start']) ? $params['start'] : '',
  346. 'end' => isset($params['end']) ? $params['end'] : ''
  347. ];
  348. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  349. $selectParams['limit'] = $pageParams['limit'];
  350. $selectParams['offset'] = $pageParams['offset'];
  351. $result = $this->objMCustomer->search($selectParams);
  352. if($result->isSuccess()){
  353. $returnData = $result->getData();
  354. $pageData = [
  355. 'pageIndex' => $params['page'],
  356. 'pageSize' => $params['pageSize'],
  357. 'pageTotal' => $returnData['total'],
  358. ];
  359. parent::sendOutput($returnData['data'], 0, $pageData);
  360. }else{
  361. parent::sendOutput($result->getData(), $result->getErrorCode());
  362. }
  363. }
  364. /**
  365. * 客户查询
  366. * @throws \Exception
  367. */
  368. public function query() {
  369. $params = $this->request->getRawJson();
  370. if( empty($params) ){
  371. $this->sendOutput('参数为空', ErrorCode::$paramError );
  372. }
  373. $selectParams = [
  374. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',//关键字:客户姓名/手机号/负责人电话
  375. 'tag' => isset($params['tag']) ? $params['tag'] : '',//标签
  376. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',//区域
  377. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  378. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  379. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',//客户启用状态
  380. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',//所属商铺
  381. 'source' => isset($params['source']) ? $params['source'] : '',//来源
  382. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',//业务员
  383. 'birthday_start' => isset($params['birthday_start']) ? $params['birthday_start'] : '',//客户生日 开始
  384. 'birthday_end' => isset($params['birthday_end']) ? $params['birthday_end'] : ''//客户生日 结束
  385. ];
  386. $pageParams = pageToOffset($params['page']?:1, $params['pageSize']?:10);
  387. $selectParams['limit'] = $pageParams['limit'];
  388. $selectParams['offset'] = $pageParams['offset'];
  389. $result = $this->objMCustomer->query($selectParams);
  390. if($result->isSuccess()){
  391. $returnData = $result->getData();
  392. $pageData = [
  393. 'pageIndex' => $params['page'],
  394. 'pageSize' => $params['pageSize'],
  395. 'pageTotal' => $returnData['total'],
  396. 'customerTotalNum' => $this->objMCustomer->getCustomerTotalNum(),
  397. 'newCustomerNum' => $this->objMCustomer->getNewCustomerNum(),
  398. 'interestCustomerNum' =>$this->objMCustomer->getInterestCustomerNum(),
  399. ];
  400. parent::sendOutput($returnData['data'], 0, $pageData);
  401. }else{
  402. parent::sendOutput($result->getData(), $result->getErrorCode());
  403. }
  404. }
  405. /**
  406. * 根据code获取客户的经纬度信息
  407. */
  408. public function getCustomerLocation() {
  409. $params = $this->request->getRawJson();
  410. $code = isset($params['code']) ? $params['code'] : '';
  411. $result = $this->objMCustomer->getCustomerLocation($code);
  412. if($result->isSuccess()){
  413. $returnData = $result->getData();
  414. parent::sendOutput($returnData);
  415. }else{
  416. parent::sendOutput($result->getData(), $result->getErrorCode());
  417. }
  418. }
  419. /**
  420. * 导出方法
  421. * @throws \Exception
  422. */
  423. public function export()
  424. {
  425. $params = $this->request->getRawJson();
  426. $selectParams = [
  427. 'keyword' => isset($params['keyword']) ? $params['keyword'] : '',
  428. 'type' => isset($params['type']) ? $params['type'] : '',
  429. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  430. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  431. 'districtCode' => isset($params['districtCode']) ? $params['districtCode'] : '',
  432. 'status' => isset($params['status']) ? $params['status'] : '',
  433. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  434. 'shopId' => isset($params['shopId']) ? $params['shopId'] : '',
  435. 'departmentId' => isset($params['departmentId']) ? $params['departmentId'] : '',
  436. 'salesManId' => isset($params['salesManId']) ? $params['salesManId'] : '',
  437. 'start' => isset($params['start']) ? $params['start'] : '',
  438. 'end' => isset($params['end']) ? $params['end'] : ''
  439. ];
  440. $selectParams['limit'] = null;
  441. $selectParams['offset'] = null;
  442. $result = $this->objMCustomer->getAllCustomer($selectParams);
  443. if($result->isSuccess() == false){
  444. parent::sendOutput($result->getData(), $result->getErrorCode());
  445. }
  446. $returnData = $result->getData();
  447. $data = $returnData['data'];
  448. //导出到本地
  449. header ( "Content-type:application/vnd.ms-excel" );
  450. header ( "Content-Disposition:filename=客户列表.csv" );
  451. header ('Cache-Control: max-age=0');
  452. $fp = fopen('php://output', 'a');
  453. $head = ['客户名称','联系人','登录账号','客户类型','商铺','销售部门','业务员','账号状态','备注']; //定义标题
  454. foreach ($head as $i => $v) {
  455. $head[$i] = mb_convert_encoding($v, 'GBK', 'utf-8'); //将中文标题转换编码,否则乱码
  456. }
  457. fputcsv($fp, $head);
  458. $limit = 10000;
  459. $num = 0; //计数器
  460. foreach ( $data as $v ) { //循环数据
  461. $num++;
  462. if($num == $limit){
  463. ob_flush(); //释放内存
  464. flush();
  465. }
  466. $rows=[
  467. 'name'=>$v['name'],
  468. 'contactName'=>empty($v['contact']) ? '' : $v['contact'][0]['name'],
  469. 'mobile' => $v['mobile'],
  470. 'customerType' => $v['customerType'],
  471. 'shopName' => $v['shopName'],
  472. 'departmentName' => $v['departmentName'],
  473. 'salesManName' => $v['salesManName'],
  474. 'enableStatus' => ($v['enableStatus'] == StatusCode::$standard) ? "启用" : "禁用",
  475. 'remark' => $v['remark'],
  476. ];
  477. foreach ( $rows as $kk => $vv){
  478. $rs[$kk] = mb_convert_encoding($vv, 'GBK', 'utf-8'); //转译编码
  479. }
  480. fputcsv($fp, $rs);
  481. $rows = [];
  482. }
  483. }
  484. public function formatCustomer()
  485. {
  486. $result = $this->objMCustomer->formatCustomer();
  487. if(!$result->isSuccess()){
  488. parent::sendOutput($result->getData(), $result->getErrorCode());
  489. }
  490. parent::sendOutput($result->getData());
  491. }
  492. /**
  493. * 充值记录列表
  494. */
  495. public function getAllRechargeBalance()
  496. {
  497. $params = $this->request->getRawJson();
  498. if(empty($params)){
  499. $this->sendOutput('参数为空', ErrorCode::$paramError);
  500. }
  501. $selectParams['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  502. foreach($selectParams as $key => $value){
  503. if(empty($value)){
  504. parent::sendOutput($key.'参数错误', ErrorCode::$paramError);
  505. }
  506. }
  507. $params['page'] = isset($params['page']) ? $params['page'] : 1;
  508. $params['pageSize'] = isset($params['pageSize']) ? $params['pageSize'] : 10;
  509. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  510. $selectParams['limit'] = $pageParams['limit'];
  511. $selectParams['offset'] = $pageParams['offset'];
  512. if(isset($params['customerId'])){
  513. $selectParams['customerId'] = $params['customerId'];
  514. }
  515. if(isset($params['userCenterId'])){
  516. $selectParams['userCenterId'] = $params['userCenterId'];
  517. }
  518. $modelResult = $this->objMCustomer->getAllRechargeBalance($selectParams);
  519. if(!$modelResult->isSuccess()){
  520. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  521. }
  522. $returnData = $modelResult->getData();
  523. $pageData = [
  524. 'pageIndex' => $params['page'],
  525. 'pageSize' => $params['pageSize'],
  526. 'pageTotal' => $returnData['total'],
  527. ];
  528. parent::sendOutput($returnData['data'], 0, $pageData);
  529. }
  530. /**
  531. * 首字母搜索客户
  532. */
  533. public function initialsSearch()
  534. {
  535. $params = $this->request->getRawJson();
  536. $data['condition'] = isset($params['condition']) ? trim($params['condition']) : '';
  537. $modelResult = $this->objMCustomer->initialsSearch($data);
  538. if(!$modelResult->isSuccess()){
  539. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  540. }
  541. parent::sendOutput($modelResult->getData());
  542. }
  543. /**
  544. * 初始化客户首字母
  545. */
  546. public function initialsCustomer()
  547. {
  548. $modelResult = $this->objMCustomer->initialsCustomer();
  549. if(!$modelResult->isSuccess()){
  550. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  551. }
  552. parent::sendOutput($modelResult->getData());
  553. }
  554. /**
  555. * Doc: (des="查询客户商品购买记录")
  556. * User: XMing
  557. * Date: 2021/3/10
  558. * Time: 10:54 上午
  559. */
  560. public function searchCustomerBuyLog()
  561. {
  562. $params = $this->request->getRawJson();
  563. $page = isset($params['page']) ? $params['page'] : 1;
  564. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  565. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  566. $params['limit'] = $pageParams['limit'];
  567. $params['offset'] = $pageParams['offset'];
  568. $export = isset($params['export']) ? $params['export'] : 0;
  569. $modelResult = $this->objMCustomer->searchCustomerBuyLog($params,$export);
  570. if(!$modelResult->isSuccess()){
  571. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  572. }
  573. $returnData = $modelResult->getData();
  574. $pageData = [
  575. 'pageIndex' => $page,
  576. 'pageSize' => $pageSize,
  577. 'pageTotal' => $returnData['total'],
  578. ];
  579. parent::sendOutput($returnData['data'], 0, $pageData);
  580. }
  581. /**
  582. * Doc: (des="销售排行")
  583. * User: XMing
  584. * Date: 2021/3/15
  585. * Time: 10:06 上午
  586. * @throws \Exception
  587. */
  588. public function salesManRank()
  589. {
  590. $params = $this->request->getRawJson();
  591. $page = isset($params['page']) ? $params['page'] : 1;
  592. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  593. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  594. $params['limit'] = $pageParams['limit'];
  595. $params['offset'] = $pageParams['offset'];
  596. $params['startTime'] = getArrayItem($params, 'startTime', strtotime(date('y-m-d 00:00:00'))) ;
  597. $params['endTime'] = getArrayItem($params, 'endTime', strtotime(date('y-m-d 23:59:59')));
  598. $params['orderStatus'] = getArrayItem($params, 'orderStatus',[4,5]);
  599. $objMOrder = new MOrder($this->onlineUserId,$this->onlineEnterpriseId);
  600. $export = isset($params['export']) ? $params['export'] : 0;
  601. $modelResult = $objMOrder->salesManRank($params,$export);
  602. if(!$modelResult->isSuccess()){
  603. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  604. }
  605. $returnData = $modelResult->getData();
  606. $pageData = [
  607. 'pageIndex' => $page,
  608. 'pageSize' => $pageSize,
  609. 'pageTotal' => $returnData['total'],
  610. ];
  611. parent::sendOutput($returnData['data'], 0, $pageData);
  612. }
  613. /**
  614. * 积分流水
  615. */
  616. public function getAllCustomerIntegralDesc()
  617. {
  618. $params = $this->request->getRawJson();
  619. $page = isset($params['page']) ? $params['page'] : 1;
  620. $pageSize = isset($params['pageSize']) ? $params['pageSize'] : 10;
  621. $pageParams = pageToOffset($params['page'], $params['pageSize']);
  622. $data['limit'] = $pageParams['limit'];
  623. $data['offset'] = $pageParams['offset'];
  624. $data['customerId'] = isset($params['customerId']) ? $params['customerId'] : '';
  625. if(empty($data['customerId'])){
  626. parent::sendOutput('customerId参数为空', ErrorCode::$paramError);
  627. }
  628. if(isset($params['star']) && !empty($params['star']) && isset($params['end']) && !empty($params['end'])){
  629. $data['createTime'] = [
  630. 'star' => $params['star'],
  631. 'end' => $params['end']
  632. ];
  633. }
  634. $modelResult = $this->objMCustomer->getAllCustomerIntegralDesc($data);
  635. if(!$modelResult->isSuccess()){
  636. parent::sendOutput($modelResult->getData(), $modelResult->getErrorCode());
  637. }
  638. $returnData = $modelResult->getData();
  639. $pageData = [
  640. 'pageIndex' => $page,
  641. 'pageSize' => $pageSize,
  642. 'pageTotal' => $returnData['total'],
  643. ];
  644. parent::sendOutput($returnData['data'], 0, $pageData);
  645. }
  646. /**
  647. * 修改积分
  648. * @throws \Exception
  649. */
  650. public function updateCustomerIntegral()
  651. {
  652. $params = $this->request->getRawJson();
  653. $data = [
  654. 'integral' => isset($params['integral']) ? $params['integral'] : '',
  655. 'customerId' => isset($params['customerId']) ? $params['customerId'] : '',
  656. 'type' => isset($params['type']) ? $params['type'] : '',
  657. ];
  658. foreach($data as $key => $value){
  659. if(empty($value)){
  660. parent::sendOutput($key.'参数为空', ErrorCode::$paramError);
  661. }
  662. }
  663. $data['desc'] = isset($params['desc']) ? $params['desc'] : '';
  664. if($this->shopId){
  665. $data['shopId'] = $this->shopId;
  666. }
  667. $result = $this->objMCustomer->updateCustomerIntegral($data);
  668. if(!$result->isSuccess()){
  669. $objCustomerCache = new CustomerCache();
  670. $objCustomerCache->delCustomerData($this->onlineEnterpriseId, $params['customerId']);
  671. parent::sendOutput($result->getData(), $result->getErrorCode());
  672. }
  673. parent::sendOutput($result->getData());
  674. }
  675. /**
  676. * 新注册未下单统计
  677. */
  678. public function noOrderCustomer()
  679. {
  680. $params = $this->request->getRawJson();
  681. if(!$params){
  682. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  683. }
  684. $data = [
  685. 'intervalDay' => getArrayItem($params, 'intervalDay', 10),
  686. 'customerName' => getArrayItem($params, 'customerName'),
  687. 'salesManId' => getArrayItem($params, 'salesManId'),
  688. 'provinceCode' => getArrayItem($params, 'provinceCode'),
  689. 'cityCode' => getArrayItem($params, 'cityCode'),
  690. 'districtCode' => getArrayItem($params, 'districtCode'),
  691. ];
  692. $page = getArrayItem($params, 'page', 1);
  693. $pageSize = getArrayItem($params, 'pageSize', 10);
  694. $pageParams = pageToOffset($page, $pageSize);
  695. $data['limit'] = $pageParams['limit'];
  696. $data['offset'] = $pageParams['offset'];
  697. $returnData = $this->objMCustomer->noOrderCustomer($data);
  698. if(!$returnData->isSuccess()){
  699. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  700. }
  701. $returnData = $returnData->getData();
  702. $pageData = [
  703. 'pageIndex' => $page,
  704. 'pageSize' => $pageSize,
  705. 'pageTotal' => $returnData['total'],
  706. ];
  707. parent::sendOutput($returnData['data'], 0, $pageData);
  708. }
  709. /**
  710. * 距离最近一次未下单统计
  711. */
  712. public function intervalNoOrderCustomer()
  713. {
  714. $params = $this->request->getRawJson();
  715. if(!$params){
  716. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  717. }
  718. $data = [
  719. 'intervalDay' => getArrayItem($params, 'intervalDay', 10),
  720. 'customerName' => getArrayItem($params, 'customerName'),
  721. 'salesManId' => getArrayItem($params, 'salesManId'),
  722. 'provinceCode' => getArrayItem($params, 'provinceCode'),
  723. 'cityCode' => getArrayItem($params, 'cityCode'),
  724. 'districtCode' => getArrayItem($params, 'districtCode'),
  725. ];
  726. $page = getArrayItem($params, 'page', 1);
  727. $pageSize = getArrayItem($params, 'pageSize', 10);
  728. $pageParams = pageToOffset($page, $pageSize);
  729. $data['limit'] = $pageParams['limit'];
  730. $data['offset'] = $pageParams['offset'];
  731. $returnData = $this->objMCustomer->intervalNoOrderCustomer($data);
  732. if(!$returnData->isSuccess()){
  733. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  734. }
  735. $returnData = $returnData->getData();
  736. $pageData = [
  737. 'pageIndex' => $page,
  738. 'pageSize' => $pageSize,
  739. 'pageTotal' => $returnData['total'],
  740. ];
  741. parent::sendOutput($returnData['data'], 0, $pageData);
  742. }
  743. /**
  744. * 拉新统计
  745. */
  746. public function recommenderStatic()
  747. {
  748. $params = $this->request->getRawJson();
  749. if(!$params){
  750. parent::sendOutput('请求参数为空', ErrorCode::$paramError);
  751. }
  752. $data = [
  753. 'startTime' => getArrayItem($params, 'startTime', 0),
  754. 'endTime' => getArrayItem($params, 'endTime', 0),
  755. 'customerId' => getArrayItem($params, 'customerId', 0),
  756. 'staffId' => getArrayItem($params, 'staffId', 0),
  757. ];
  758. $page = getArrayItem($params, 'page', 1);
  759. $pageSize = getArrayItem($params, 'pageSize', 10);
  760. $pageParams = pageToOffset($page, $pageSize);
  761. $data['limit'] = $pageParams['limit'];
  762. $data['offset'] = $pageParams['offset'];
  763. $returnData = $this->objMCustomer->recommenderStatic($data);
  764. if(!$returnData->isSuccess()){
  765. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  766. }
  767. $returnData = $returnData->getData();
  768. $pageData = [
  769. 'pageIndex' => $page,
  770. 'pageSize' => $pageSize,
  771. 'pageTotal' => $returnData['total'],
  772. ];
  773. parent::sendOutput($returnData['data'], 0, $pageData);
  774. }
  775. //审核,打款公共方法
  776. public function updateReflectDetail()
  777. {
  778. $params = $this->request->getRawJson();
  779. if (empty($params['id']) || empty($params['createTime'])) {
  780. $this->sendOutput('参数为空', ErrorCode::$paramError);
  781. }
  782. $result = $this->objMReflectDetail->updateReflectDetail($params);
  783. if ($result->isSuccess()) {
  784. parent::sendOutput($result->getData());
  785. } else {
  786. parent::sendOutput($result->getData(), $result->getErrorCode());
  787. }
  788. }
  789. /**
  790. * 所有提现记录
  791. */
  792. public function getAllReflectDetail()
  793. {
  794. $params = $this->request->getRawJson();
  795. if (empty($params)) {
  796. $this->sendOutput('参数为空', ErrorCode::$paramError);
  797. }
  798. $pageParams = pageToOffset($params['page'] ?: 1, $params['pageSize'] ?: 10);
  799. $params['limit'] = $pageParams['limit'];
  800. $params['offset'] = $pageParams['offset'];
  801. $params['start'] = getArrayItem($params,'start',"");
  802. $params['end'] = getArrayItem($params,'end',"");
  803. $params['customerId'] = getArrayItem($params,'customerId', '');
  804. $params['reflectStatus'] = getArrayItem($params,'reflectStatus', '');
  805. $params['auditStatus'] = getArrayItem($params,'auditStatus', '');
  806. $params['reflectType'] = getArrayItem($params,'reflectType', '');//提现类型
  807. $returnData = $this->objMReflectDetail->getAllReflectDetail($params);
  808. if ($returnData->isSuccess()) {
  809. $returnData = $returnData->getData();
  810. $pageData = [
  811. 'pageIndex' => $params['page'],
  812. 'pageSize' => $params['pageSize'],
  813. 'pageTotal' => $returnData['total'],
  814. ];
  815. parent::sendOutput($returnData['data'], 0, $pageData);
  816. } else {
  817. parent::sendOutput($returnData->getData(), ErrorCode::$dberror);
  818. }
  819. }
  820. /**
  821. * 后台充值
  822. */
  823. public function rechargeMemberBalance()
  824. {
  825. $params = $this->request->getRawJson();
  826. if (empty($params)) {
  827. $this->sendOutput('参数为空', ErrorCode::$paramError);
  828. }
  829. //记录流水
  830. $memberBalanceDetailData = [
  831. 'customerId' => $params['customerId'],
  832. 'type' => $params['type'],
  833. 'userCenterId' => $this->onlineUserId,
  834. 'money' =>$params['money'],
  835. 'purpose' => isset($params['purpose']) ? $params['purpose']: 0,
  836. 'orderIds' =>'',
  837. 'remark' => '充值'.$params['money'],
  838. 'financeType' => '会员余额充值',
  839. 'accountId' => 0,
  840. 'accountName' => '',
  841. 'accountNumber' => '',
  842. 'explain' => '',
  843. ];
  844. foreach ($memberBalanceDetailData as $k =>$v) {//,'accountId','accountName','accountNumber'
  845. if(in_array($k, ['customerId','money','purpose']) && empty($v)) {
  846. $this->sendOutput('请输入'.$k, ErrorCode::$paramError);
  847. }
  848. }
  849. $result = $this->objMMemberBalanceDetail->addMemberBalanceDetail($memberBalanceDetailData,$isbackstage=true);
  850. if (!$result->isSuccess()) {
  851. parent::sendOutput($result->getData(), $result->getErrorCode());
  852. }
  853. parent::sendOutput($result->getData());
  854. }
  855. /**
  856. * 接收导入客户数据参数
  857. * @throws \Exception
  858. */
  859. public function getCustomerBasicImportParams()
  860. {
  861. //获取数据文件
  862. $params = $this->request->getRawJson();
  863. //企业id
  864. $enterpriseId = $this->onlineEnterpriseId;
  865. //引用dao
  866. $objDSysAreaChina = new DSysAreaChina(); //省市区dao
  867. $objDShop = new DShop();//商铺dao
  868. $objDShop->setTable('qianniao_shop_1' );
  869. $objDDepartment = new DDepartment();//销售部门dao
  870. $objDDepartment->setTable('qianniao_department_' . $enterpriseId);
  871. $objDDStaff = new DStaff();//员工表
  872. $objDDStaff->setTable('qianniao_staff_' . $enterpriseId);
  873. //获取数据
  874. $postArray = [];
  875. foreach ($params as $value) {
  876. $customerArray = $value;
  877. //客户信息
  878. $name = isset($customerArray['name']) ? trim($customerArray['name']) : '';//客户名称
  879. $mobile = isset($customerArray['mobile']) ? trim($customerArray['mobile']) : '';//登录账号
  880. $contacts = isset($customerArray['contacts']) ? trim($customerArray['contacts']) : '';//联系人
  881. $nameMobile = isset($customerArray['nameMobile']) ? trim($customerArray['nameMobile']) : 4;//联系人电话
  882. $birthday = isset($customerArray['birthday']) ? trim($customerArray['birthday']) : '';//客户生日
  883. $remark = isset($customerArray['remark']) ? trim($customerArray['remark']) : '';//客户备注
  884. $customerType = isset($customerArray['type']) ? trim($customerArray['type']) : '';//客户类型
  885. //省市区
  886. $provinceName = isset($customerArray['provinceName']) ? trim($customerArray['provinceName']) : '';//省名称
  887. $cityName = isset($customerArray['cityName']) ? trim($customerArray['cityName']) : '';//市名称
  888. $areaName = isset($customerArray['areaName']) ? trim($customerArray['areaName']) : '';//区名称
  889. $address = isset($customerArray['address']) ? trim($customerArray['address']) : '';//详细地址
  890. $shopName = isset($customerArray['shopName']) ? trim($customerArray['shopName']) : '';//商铺名称
  891. $departmentId = isset($customerArray['departmentId']) ? trim($customerArray['departmentId']) : '';//销售部门id
  892. $salesManId = isset($customerArray['salesManId']) ? trim($customerArray['salesManId']) : '';//业务员Id
  893. $salesManCode = createCode(StatusCode::$code['staff']['prefix'],$salesManId, StatusCode::$code['staff']['length']);
  894. if (empty($name)) {
  895. continue;
  896. }
  897. // //业务员
  898. // $salesManId = 0;
  899. // $salesManCode ='';
  900. // if(!empty($salesManName)){
  901. // $dbResult = $objDDStaff->get(['staffName'=> $salesManName]);
  902. // if($dbResult !== false){
  903. // $salesManId = $dbResult['id'];
  904. // $salesManCode = createCode(StatusCode::$code['staff']['prefix'],$salesManId, StatusCode::$code['staff']['length']);
  905. //
  906. // }
  907. // }
  908. //商铺
  909. $shopId = 0;
  910. if(!empty($shopName)){
  911. $dbResult = $objDShop->get(['name'=>$shopName]);
  912. if($dbResult !== false){
  913. $shopId = $dbResult['id'];
  914. }
  915. }
  916. //销售部门
  917. // $departmentId = 0;
  918. // if(!empty($departmentName)){
  919. // $dbResult = $objDDepartment->get(['departmentName'=>$departmentName]);
  920. // if($dbResult !== false){
  921. // $departmentId = $dbResult['id'];
  922. // }
  923. // }
  924. //省市区
  925. $provinceCode ='';
  926. $cityCode = '';
  927. $areaCode = '';
  928. if(!empty($provinceName)){
  929. //省编码
  930. $dbResult = $objDSysAreaChina->get(['name'=>$provinceName]);
  931. if($dbResult !== false){
  932. $provinceCode = $dbResult['code'];
  933. //市编码
  934. $dbResult = $objDSysAreaChina->get(['name'=>$cityName,'pcode'=>$provinceCode]);
  935. if($dbResult !== false){
  936. $cityCode = $dbResult['code'];
  937. //区编码
  938. $dbResult = $objDSysAreaChina->get(['name'=>$areaName,'pcode'=>$cityCode]);
  939. if($dbResult !== false){
  940. $areaCode = $dbResult['code'];
  941. }
  942. }
  943. }
  944. }
  945. $postData = array (
  946. 'tempSave' => '',
  947. 'latitude' => '',
  948. 'longitude' => '',
  949. 'password' => '',
  950. 'area' => '',
  951. 'mobile' => $mobile,
  952. 'enableStatus' => 5,
  953. 'name' => $name,
  954. 'code' => '',
  955. 'type' => $customerType,
  956. 'provinceCode' => $provinceCode,
  957. 'cityCode' => $cityCode,
  958. 'districtCode' => $areaCode,
  959. 'address' => $address,
  960. 'managerMobile' => '',
  961. 'shopId' => $shopId,
  962. 'departmentId' => $departmentId,
  963. 'salesManId' => $salesManId,
  964. 'salesManCode' => $salesManCode,
  965. 'salesManName' => '',
  966. 'birthday' => $birthday,
  967. 'remark' => $remark,
  968. 'reservoirId' => $customerType,
  969. 'recommenderType' => '',
  970. 'recommenderId' => '',
  971. 'extend' =>
  972. array (
  973. 'license' => '',
  974. ),
  975. 'contact' =>
  976. array (
  977. 'area' => '',
  978. 'name' => $contacts,
  979. 'mobile' => $nameMobile,
  980. 'provinceCode' => $provinceCode,
  981. 'cityCode' => $cityCode,
  982. 'districtCode' => $areaCode,
  983. 'address' => $address,
  984. ),
  985. );
  986. $postArray[] = $postData;
  987. }
  988. return $postArray;
  989. }
  990. /**
  991. * 导入客户资料
  992. * @throws \Exception
  993. */
  994. public function customerImport()
  995. {
  996. //把页面传来的参数对应到符合的字段中全部传递过来;
  997. $paramsArray = self::getCustomerBasicImportParams();
  998. if (empty($paramsArray)) {
  999. $this->sendOutput('参数为空', ErrorCode::$paramError);
  1000. }
  1001. $customerBasic = [];
  1002. foreach ($paramsArray as $params) {
  1003. $customerData = [
  1004. 'mobile' => isset($params['mobile']) ? $params['mobile'] : '',//账号
  1005. 'name' => isset($params['name']) ? $params['name'] : '',
  1006. 'type' => isset($params['type']) ? $params['type'] : '',//客户类型
  1007. ];
  1008. //非暂存则验空
  1009. if (!isset($params['tempSave']) || $params['tempSave'] == false) {
  1010. foreach ($customerData as $key => $value) {
  1011. if (empty($value) && $value !== 0) {
  1012. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  1013. }
  1014. }
  1015. }
  1016. $customerData['enableStatus'] = isset($params['enableStatus']) ? $params['enableStatus'] : StatusCode::$standard;//启用状态
  1017. $customerData['contact'] = isset($params['contact']) ? $params['contact'] : '';
  1018. $customerData['provinceCode'] = isset($params['provinceCode']) ? $params['provinceCode'] : '';
  1019. $customerData['cityCode'] = isset($params['cityCode']) ? $params['cityCode'] : '';
  1020. $customerData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : '';
  1021. $customerData['shopId'] = isset($params['shopId']) ? $params['shopId'] : '';
  1022. $customerData['longitude'] = isset($params['longitude']) ? $params['longitude'] : '';
  1023. $customerData['latitude'] = isset($params['latitude']) ? $params['latitude'] : '';
  1024. $customerData['tempSave'] = isset($params['tempSave']) ? $params['tempSave'] : false;
  1025. $customerData['password'] = isset($params['password']) ? $params['password'] : '';//密码
  1026. $customerData['address'] = isset($params['address']) ? $params['address'] : '';
  1027. $customerData['managerMobile'] = isset($params['managerMobile']) ? $params['managerMobile'] : '';
  1028. $customerData['avatar'] = isset($params['avatar']) ? $params['avatar'] : '';//客户头像
  1029. // $customerData['sortingId'] = isset($params['sortingId']) ? $params['sortingId'] : '';
  1030. $customerData['departmentId'] = isset($params['departmentId']) ? $params['departmentId'] : '';
  1031. $customerData['salesManId'] = isset($params['salesManId']) ? $params['salesManId'] : '';
  1032. $customerData['salesManCode'] = isset($params['salesManCode']) ? $params['salesManCode'] : '';
  1033. $customerData['salesManName'] = isset($params['salesManName']) ? $params['salesManName'] : '';
  1034. $customerData['birthday'] = isset($params['birthday']) ? $params['birthday'] : '';
  1035. $customerData['remark'] = isset($params['remark']) ? $params['remark'] : '';
  1036. $customerData['deleteStatus'] = StatusCode::$standard;
  1037. $customerData['status'] = isset($params['status']) ? $params['status'] : '';
  1038. $customerData['area'] = isset($params['area']) ? $params['area'] : [];
  1039. $customerData['shopName'] = isset($params['shopName']) ? $params['shopName'] : '';
  1040. $customerData['reservoirId'] = isset($params['reservoirId']) ? $params['reservoirId'] : '';
  1041. (isset($params['extend']) && !empty($params['extend'])) && $customerData['extend'] = json_encode($params['extend']);
  1042. $customerData['memberBalance'] = getArrayItem($params, 'memberBalance', '');
  1043. $customerData['recommenderType'] = getArrayItem($params, 'recommenderType', '');
  1044. $customerData['recommenderId'] = getArrayItem($params, 'recommenderId', '');
  1045. $customerData['createTime'] = time();
  1046. $customerData['updateTime'] = time();
  1047. //联系人信息
  1048. $customerData['contact'] = getArrayItem($params, 'contact', []);
  1049. $customerBasic[] = $customerData;
  1050. }
  1051. unset($customerData);
  1052. $total = 0;
  1053. $true = 0;
  1054. $false = 0;
  1055. $exportError = date('Ymd_H:i:s').'.txt';
  1056. foreach ($customerBasic as $key => $customerData){
  1057. if ($customerData['tempSave']) {
  1058. parent::sendOutput('暂存成功');
  1059. }
  1060. unset($customerData['tempSave']);
  1061. unset($customerData['area']);
  1062. unset($customerData['shopName']);
  1063. $result = $this->objMCustomer ->addCustomer($customerData);
  1064. if(!$result->isSuccess()){
  1065. if(!is_dir(UPLOAD_FILE_PATH.'/exportError/')){
  1066. mkdir(UPLOAD_FILE_PATH.'/exportError/',0777,true);
  1067. }
  1068. $a = $key+1;
  1069. file_put_contents(UPLOAD_FILE_PATH.'/exportError/'.$exportError,'第 '. $a .'行导入失败,原因'.var_export($result->getData().$result->getErrorCode(),true).PHP_EOL,FILE_APPEND);
  1070. $false++;
  1071. } else {
  1072. $true++;
  1073. }
  1074. $total++;
  1075. }
  1076. $returnData = [
  1077. 'successMsg' => '共'.$total.'条客户数据,成功'.$true.'条客户数据,失败'.$false.'条客户数据',
  1078. 'errorNum' => $false,
  1079. 'url' => URL_UPLOAD.'exportError/'.$exportError,
  1080. ];
  1081. parent::sendOutput($returnData);
  1082. }
  1083. /**
  1084. * 客户分布
  1085. */
  1086. public function getCustomerDistributed()
  1087. {
  1088. $returnData = $this->objMCustomer->getCustomerDistributed();
  1089. if(!$returnData->isSuccess()){
  1090. parent::sendOutput($returnData->getData(), $returnData->getErrorCode());
  1091. }
  1092. parent::sendOutput($returnData->getData());
  1093. }
  1094. /**
  1095. * 批量设置客户类型
  1096. */
  1097. public function setCustomerType()
  1098. {
  1099. $params = $this->request->getRawJson();
  1100. if (empty($params)) {
  1101. $this->sendOutput('参数为空', ErrorCode::$paramError);
  1102. }
  1103. $params['customerIds'] = getArrayItem($params,'customerIds',[]);
  1104. $params['type'] = getArrayItem($params,'type',0);
  1105. $result = $this->objMCustomer->setCustomerType($params);
  1106. if($result->isSuccess()){
  1107. parent::sendOutput($result->getData());
  1108. }else{
  1109. parent::sendOutput($result->getData(), $result->getErrorCode());
  1110. }
  1111. }
  1112. }