Supplier.Class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. <?php
  2. /**
  3. * 供应商
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/11
  7. * Time: 14:38
  8. */
  9. namespace JinDouYun\Controller\Purchase;
  10. use JinDouYun\Controller\BaseController;
  11. use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
  12. use Mall\Framework\Core\ErrorCode;
  13. use JinDouYun\Model\Purchase\MSupplier;
  14. class Supplier extends BaseController
  15. {
  16. private $objMSupplier;
  17. /**
  18. * Order constructor.
  19. * @param bool $isCheckAcl
  20. * @param bool $isMustLogin
  21. * @throws \Exception
  22. */
  23. public function __construct($isCheckAcl = true, $isMustLogin = true)
  24. {
  25. parent::__construct($isCheckAcl, $isMustLogin);
  26. $this->objMSupplier = new MSupplier($this->onlineUserId, $this->onlineEnterpriseId);
  27. }
  28. /**
  29. * 添加,编辑供应商
  30. * @return array
  31. */
  32. public function commonFieldFilter()
  33. {
  34. $params = $this->request->getRawJson();
  35. if (empty($params)) {
  36. $this->sendOutput('参数为空', ErrorCode::$paramError);
  37. }
  38. $data = [
  39. 'title' => isset($params['title']) ? $params['title'] : '',
  40. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  41. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  42. 'realName' => isset($params['realName']) ? $params['realName'] : '',
  43. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  44. ];
  45. foreach ($data as $key => $value) {
  46. if (empty($value) && $value !== 0) {
  47. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  48. }
  49. }
  50. $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : null;
  51. $data['address'] = isset($params['address']) ? $params['address'] : null;
  52. $data['mobile'] = isset($params['mobile']) ? $params['mobile'] : null;
  53. $data['sex'] = isset($params['sex']) ? $params['sex'] : null;
  54. $data['phone'] = isset($params['phone']) ? $params['phone'] : null;
  55. $data['position'] = isset($params['position']) ? $params['position'] : null;
  56. $data['email'] = isset($params['email']) ? $params['email'] : null;
  57. $data['remark'] = isset($params['remark']) ? $params['remark'] : null;
  58. $data['accountName'] = isset($params['accountName']) ? $params['accountName'] : null;
  59. $data['bankName'] = isset($params['bankName']) ? $params['bankName'] : null;
  60. $data['bankCard'] = isset($params['bankCard']) ? $params['bankCard'] : null;
  61. return $data;
  62. }
  63. /**
  64. * 添加供应商
  65. * @throws \Exception
  66. */
  67. public function addSupplier()
  68. {
  69. $data = $this->commonFieldFilter();
  70. $result = $this->objMSupplier->addSupplier($data);
  71. if ($result->isSuccess()) {
  72. parent::sendOutput($result->getData());
  73. } else {
  74. parent::sendOutput($result->getData(), $result->getErrorCode());
  75. }
  76. }
  77. /**
  78. * 添加供应商为用户
  79. * @param $params
  80. * @return ResultWrapper
  81. */
  82. public function addSupplierUserCenter()
  83. {
  84. $id = $this->request->param('request_id');
  85. if (!$id) {
  86. $this->sendOutput('参数错误', ErrorCode::$paramError);
  87. }
  88. $result = $this->objMSupplier->addSupplierUserCenter(['id' => $id]);
  89. if ($result->isSuccess()) {
  90. parent::sendOutput($result->getData());
  91. } else {
  92. parent::sendOutput($result->getData(), $result->getErrorCode());
  93. }
  94. }
  95. /**
  96. * 供应商信息
  97. */
  98. public function getSupplierInfoById()
  99. {
  100. $id = $this->request->param('request_id');
  101. if (!$id) {
  102. $this->sendOutput('参数错误', ErrorCode::$paramError);
  103. }
  104. $result = $this->objMSupplier->getSupplierInfoById($id);
  105. if ($result->isSuccess()) {
  106. $resultData = $result->getData();
  107. $this->sendOutput($resultData);
  108. }
  109. $this->sendOutput($result->getData(), $result->getErrorCode());
  110. }
  111. /**
  112. * 获取供应商信息
  113. */
  114. public function getSupplierByUserCenterId()
  115. {
  116. $result = $this->objMSupplier->getSupplierByUserCenterId($this->onlineUserId);
  117. if ($result->isSuccess()) {
  118. $resultData = $result->getData();
  119. $this->sendOutput($resultData);
  120. }
  121. $this->sendOutput($result->getData(), $result->getErrorCode());
  122. }
  123. /**
  124. * 编辑供应商信息
  125. */
  126. public function editSupplier()
  127. {
  128. $id = $this->request->param('request_id');
  129. if (empty($id)) {
  130. $this->sendOutput('参数错误', ErrorCode::$paramError);
  131. }
  132. $data = $this->commonFieldFilter();
  133. $data['id'] = $id;
  134. $result = $this->objMSupplier->editSupplier($data);
  135. if ($result->isSuccess()) {
  136. parent::sendOutput($result->getData());
  137. } else {
  138. parent::sendOutput($result->getData(), $result->getErrorCode());
  139. }
  140. }
  141. /**
  142. * 更新供应商状态
  143. */
  144. public function updateEnableStatus()
  145. {
  146. $params['id'] = $this->request->param('request_id');
  147. $params['enableStatus'] = $this->request->param('enableStatus');//5正常 4隐藏
  148. foreach ($params as $key => $value) {
  149. if (empty($value)) {
  150. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  151. }
  152. }
  153. $result = $this->objMSupplier->updateEnableStatus($params);
  154. if ($result->isSuccess()) {
  155. parent::sendOutput($result->getData());
  156. } else {
  157. parent::sendOutput($result->getData(), $result->getErrorCode());
  158. }
  159. }
  160. /**
  161. * 删除供应商
  162. */
  163. public function delSupplier()
  164. {
  165. $id = $this->request->param('request_id');
  166. if (!$id) {
  167. $this->sendOutput('参数错误', ErrorCode::$paramError);
  168. }
  169. if (!is_array($id)) {
  170. $id = [$id];
  171. }
  172. $result = $this->objMSupplier->delSupplier($id);
  173. if ($result->isSuccess()) {
  174. parent::sendOutput($result->getData());
  175. } else {
  176. parent::sendOutput($result->getData(), $result->getErrorCode());
  177. }
  178. }
  179. /**
  180. * 获取供应商列表
  181. */
  182. public function getAllSupplier()
  183. {
  184. $page = $this->request->param('page') ? $this->request->param('page') : 1;
  185. $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10;
  186. $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : '';
  187. $enableStatus = $this->request->param('enableStatus') ? $this->request->param('enableStatus') : '';
  188. $offset = ($page - 1) * $pageSize;
  189. $selectParams = [
  190. 'limit' => $pageSize,
  191. 'offset' => $offset,
  192. ];
  193. if (!empty($keyword)) $selectParams['keyword'] = $keyword;
  194. if (!empty($enableStatus)) $selectParams['enableStatus'] = $enableStatus;
  195. $orderData = $this->objMSupplier->getAllSupplier($selectParams);
  196. if ($orderData->isSuccess()) {
  197. $returnData = $orderData->getData();
  198. $pageData = [
  199. 'pageIndex' => $page,
  200. 'pageSize' => $pageSize,
  201. 'pageTotal' => $returnData['total'],
  202. ];
  203. parent::sendOutput($returnData['data'], 0, $pageData);
  204. } else {
  205. parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
  206. }
  207. }
  208. /**
  209. * Doc: (des="")
  210. * User: XMing
  211. * Date: 2020/12/19
  212. * Time: 11:06 上午
  213. */
  214. public function getWithdrawal()
  215. {
  216. $result = $this->objMSupplier->getWithdrawal($this->supplierId);
  217. if ($result->isSuccess()) {
  218. parent::sendOutput($result->getData());
  219. }
  220. parent::sendOutput($result->getData(), $result->getErrorCode());
  221. }
  222. public function test()
  223. {
  224. $data = $this->objMSupplier->todaySupplierRanking();
  225. print_r($data);
  226. }
  227. /**
  228. * Doc: (des="供应商数据")
  229. * User: XMing
  230. * Date: 2020/12/26
  231. * Time: 4:35 下午
  232. */
  233. public function statistics()
  234. {
  235. if (empty($this->supplierId)){
  236. parent::sendOutput('supplierId参数错误',ErrorCode::$paramError);
  237. }
  238. $result = $this->objMSupplier->statistics($this->supplierId);
  239. if (!$result->isSuccess()){
  240. parent::sendOutput($result->getData(),$result->getErrorCode());
  241. }
  242. parent::sendOutput($result->getData());
  243. }
  244. /**
  245. * 接收导入客户数据参数
  246. * @throws \Exception
  247. */
  248. public function getSupplierBasicImportParams()
  249. {
  250. //获取数据文件
  251. $params = $this->request->getRawJson();
  252. //企业id
  253. $enterpriseId = $this->onlineEnterpriseId;
  254. //引用dao
  255. $objDSysAreaChina = new DSysAreaChina(); //省市区dao
  256. //获取数据
  257. $postArray = [];
  258. foreach ($params as $value) {
  259. $supplierArray = $value;
  260. //供应商导入信息
  261. $title = isset($supplierArray['title']) ? trim($supplierArray['title']) : '';//供应商名称
  262. $realName = isset($supplierArray['realName']) ? trim($supplierArray['realName']) : '';//联系人姓名
  263. $mobile = isset($supplierArray['mobile']) ? trim($supplierArray['mobile']) : '';//手机号
  264. $phone = isset($supplierArray['phone']) ? trim($supplierArray['phone']) : 4;//电话
  265. $position = isset($supplierArray['position']) ? trim($supplierArray['position']) : '';//职务
  266. $email = isset($supplierArray['email']) ? trim($supplierArray['email']) : '';//邮件
  267. $remark = isset($supplierArray['remark']) ? trim($supplierArray['remark']) : '';//客户备注
  268. $accountName = isset($supplierArray['accountName']) ? trim($supplierArray['accountName']) : '';//户名
  269. $bankName = isset($supplierArray['bankName']) ? trim($supplierArray['bankName']) : '';//开户行
  270. $bankCard = isset($supplierArray['bankCard']) ? trim($supplierArray['bankCard']) : '';//银行卡号
  271. //省市区
  272. $provinceName = isset($supplierArray['provinceName']) ? trim($supplierArray['provinceName']) : '';//省名称
  273. $cityName = isset($supplierArray['cityName']) ? trim($supplierArray['cityName']) : '';//市名称
  274. $areaName = isset($supplierArray['areaName']) ? trim($supplierArray['areaName']) : '';//区名称
  275. $address = isset($supplierArray['address']) ? trim($supplierArray['address']) : '';//详细地址
  276. if (empty($title)) {
  277. continue;
  278. }
  279. //省市区
  280. $provinceCode ='';
  281. $cityCode = '';
  282. $areaCode = '';
  283. if(!empty($provinceName)){
  284. //省编码
  285. $dbResult = $objDSysAreaChina->get(['name'=>$provinceName]);
  286. if($dbResult !== false){
  287. $provinceCode = $dbResult['code'];
  288. //市编码
  289. $dbResult = $objDSysAreaChina->get(['name'=>$cityName,'pcode'=>$provinceCode]);
  290. if($dbResult !== false){
  291. $cityCode = $dbResult['code'];
  292. //区编码
  293. $dbResult = $objDSysAreaChina->get(['name'=>$areaName,'pcode'=>$cityCode]);
  294. if($dbResult !== false){
  295. $areaCode = $dbResult['code'];
  296. }
  297. }
  298. }
  299. }
  300. $enableStatus = 5;
  301. $postData = array(
  302. 'title' => $title,
  303. 'provinceCode' => $provinceCode,
  304. 'cityCode' => $cityCode,
  305. 'districtCode' => $areaCode,
  306. 'address' => $address,
  307. 'realName' => $realName,
  308. 'mobile' => $mobile,
  309. 'enableStatus' => $enableStatus,
  310. 'sex' => 0,
  311. 'phone' => $phone,
  312. 'position' => $position,
  313. 'email' => $email,
  314. 'remark' => $remark,
  315. 'accountName' => $accountName,
  316. 'bankName' => $bankName,
  317. 'bankCard' => $bankCard,
  318. );
  319. $postArray[] = $postData;
  320. }
  321. return $postArray;
  322. }
  323. /**
  324. * 导入供应商
  325. * @throws \Exception
  326. */
  327. public function supplierImport()
  328. {
  329. //把页面传来的参数对应到符合的字段中全部传递过来;
  330. $paramsArray = self::getSupplierBasicImportParams();
  331. if (empty($paramsArray)) {
  332. $this->sendOutput('参数为空', ErrorCode::$paramError);
  333. }
  334. $supplierBasic = [];
  335. foreach ($paramsArray as $params){
  336. $supplierBasicData = [
  337. 'title' => isset($params['title']) ? $params['title'] : '',
  338. 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  339. 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
  340. 'realName' => isset($params['realName']) ? $params['realName'] : '',
  341. 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
  342. ];
  343. foreach ($supplierBasicData as $key => $value) {
  344. if (empty($value) && $value !== 0) {
  345. $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
  346. }
  347. }
  348. $supplierBasicData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : null;
  349. $supplierBasicData['address'] = isset($params['address']) ? $params['address'] : null;
  350. $supplierBasicData['mobile'] = isset($params['mobile']) ? $params['mobile'] : null;
  351. $supplierBasicData['sex'] = isset($params['sex']) ? $params['sex'] : null;
  352. $supplierBasicData['phone'] = isset($params['phone']) ? $params['phone'] : null;
  353. $supplierBasicData['position'] = isset($params['position']) ? $params['position'] : null;
  354. $supplierBasicData['email'] = isset($params['email']) ? $params['email'] : null;
  355. $supplierBasicData['remark'] = isset($params['remark']) ? $params['remark'] : null;
  356. $supplierBasicData['accountName'] = isset($params['accountName']) ? $params['accountName'] : null;
  357. $supplierBasicData['bankName'] = isset($params['bankName']) ? $params['bankName'] : null;
  358. $supplierBasicData['bankCard'] = isset($params['bankCard']) ? $params['bankCard'] : null;
  359. $supplierBasic[] = $supplierBasicData;
  360. }
  361. unset($supplierBasicData);
  362. $total = 0;
  363. $true = 0;
  364. $false = 0;
  365. foreach ($supplierBasic as $key => $supplierBasicData){
  366. $result = $this->objMSupplier->addSupplier($supplierBasicData);
  367. if(!$result->isSuccess()){
  368. $false++;
  369. } else {
  370. $true++;
  371. }
  372. $total++;
  373. }
  374. $return = "共导入'$total'条数据,成功'$true'条数据,失败'$false'条数据";
  375. parent::sendOutput($return);
  376. }
  377. }