123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- <?php
- /**
- * 供应商
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/11
- * Time: 14:38
- */
- namespace JinDouYun\Controller\Purchase;
- use JinDouYun\Controller\BaseController;
- use JinDouYun\Dao\SysAreaChina\DSysAreaChina;
- use Mall\Framework\Core\ErrorCode;
- use JinDouYun\Model\Purchase\MSupplier;
- class Supplier extends BaseController
- {
- private $objMSupplier;
- /**
- * Order constructor.
- * @param bool $isCheckAcl
- * @param bool $isMustLogin
- * @throws \Exception
- */
- public function __construct($isCheckAcl = true, $isMustLogin = true)
- {
- parent::__construct($isCheckAcl, $isMustLogin);
- $this->objMSupplier = new MSupplier($this->onlineUserId, $this->onlineEnterpriseId);
- }
- /**
- * 添加,编辑供应商
- * @return array
- */
- public function commonFieldFilter()
- {
- $params = $this->request->getRawJson();
- if (empty($params)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
- $data = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
- 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
- 'realName' => isset($params['realName']) ? $params['realName'] : '',
- 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
- ];
- foreach ($data as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $data['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : null;
- $data['address'] = isset($params['address']) ? $params['address'] : null;
- $data['mobile'] = isset($params['mobile']) ? $params['mobile'] : null;
- $data['sex'] = isset($params['sex']) ? $params['sex'] : null;
- $data['phone'] = isset($params['phone']) ? $params['phone'] : null;
- $data['position'] = isset($params['position']) ? $params['position'] : null;
- $data['email'] = isset($params['email']) ? $params['email'] : null;
- $data['remark'] = isset($params['remark']) ? $params['remark'] : null;
- $data['accountName'] = isset($params['accountName']) ? $params['accountName'] : null;
- $data['bankName'] = isset($params['bankName']) ? $params['bankName'] : null;
- $data['bankCard'] = isset($params['bankCard']) ? $params['bankCard'] : null;
- return $data;
- }
- /**
- * 添加供应商
- * @throws \Exception
- */
- public function addSupplier()
- {
- $data = $this->commonFieldFilter();
- $result = $this->objMSupplier->addSupplier($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 添加供应商为用户
- * @param $params
- * @return ResultWrapper
- */
- public function addSupplierUserCenter()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMSupplier->addSupplierUserCenter(['id' => $id]);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 供应商信息
- */
- public function getSupplierInfoById()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $result = $this->objMSupplier->getSupplierInfoById($id);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- $this->sendOutput($resultData);
- }
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 获取供应商信息
- */
- public function getSupplierByUserCenterId()
- {
- $result = $this->objMSupplier->getSupplierByUserCenterId($this->onlineUserId);
- if ($result->isSuccess()) {
- $resultData = $result->getData();
- $this->sendOutput($resultData);
- }
- $this->sendOutput($result->getData(), $result->getErrorCode());
- }
- /**
- * 编辑供应商信息
- */
- public function editSupplier()
- {
- $id = $this->request->param('request_id');
- if (empty($id)) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- $data = $this->commonFieldFilter();
- $data['id'] = $id;
- $result = $this->objMSupplier->editSupplier($data);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 更新供应商状态
- */
- public function updateEnableStatus()
- {
- $params['id'] = $this->request->param('request_id');
- $params['enableStatus'] = $this->request->param('enableStatus');//5正常 4隐藏
- foreach ($params as $key => $value) {
- if (empty($value)) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $result = $this->objMSupplier->updateEnableStatus($params);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 删除供应商
- */
- public function delSupplier()
- {
- $id = $this->request->param('request_id');
- if (!$id) {
- $this->sendOutput('参数错误', ErrorCode::$paramError);
- }
- if (!is_array($id)) {
- $id = [$id];
- }
- $result = $this->objMSupplier->delSupplier($id);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- } else {
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- }
- /**
- * 获取供应商列表
- */
- public function getAllSupplier()
- {
- $page = $this->request->param('page') ? $this->request->param('page') : 1;
- $pageSize = $this->request->param('pageSize') ? $this->request->param('pageSize') : 10;
- $keyword = $this->request->param('keyword') ? $this->request->param('keyword') : '';
- $enableStatus = $this->request->param('enableStatus') ? $this->request->param('enableStatus') : '';
- $offset = ($page - 1) * $pageSize;
- $selectParams = [
- 'limit' => $pageSize,
- 'offset' => $offset,
- ];
- if (!empty($keyword)) $selectParams['keyword'] = $keyword;
- if (!empty($enableStatus)) $selectParams['enableStatus'] = $enableStatus;
- $orderData = $this->objMSupplier->getAllSupplier($selectParams);
- if ($orderData->isSuccess()) {
- $returnData = $orderData->getData();
- $pageData = [
- 'pageIndex' => $page,
- 'pageSize' => $pageSize,
- 'pageTotal' => $returnData['total'],
- ];
- parent::sendOutput($returnData['data'], 0, $pageData);
- } else {
- parent::sendOutput($orderData->getData(), ErrorCode::$dberror);
- }
- }
- /**
- * Doc: (des="")
- * User: XMing
- * Date: 2020/12/19
- * Time: 11:06 上午
- */
- public function getWithdrawal()
- {
- $result = $this->objMSupplier->getWithdrawal($this->supplierId);
- if ($result->isSuccess()) {
- parent::sendOutput($result->getData());
- }
- parent::sendOutput($result->getData(), $result->getErrorCode());
- }
- public function test()
- {
- $data = $this->objMSupplier->todaySupplierRanking();
- print_r($data);
- }
- /**
- * Doc: (des="供应商数据")
- * User: XMing
- * Date: 2020/12/26
- * Time: 4:35 下午
- */
- public function statistics()
- {
- if (empty($this->supplierId)){
- parent::sendOutput('supplierId参数错误',ErrorCode::$paramError);
- }
- $result = $this->objMSupplier->statistics($this->supplierId);
- if (!$result->isSuccess()){
- parent::sendOutput($result->getData(),$result->getErrorCode());
- }
- parent::sendOutput($result->getData());
- }
- /**
- * 接收导入客户数据参数
- * @throws \Exception
- */
- public function getSupplierBasicImportParams()
- {
-
- //获取数据文件
- $params = $this->request->getRawJson();
- //企业id
- $enterpriseId = $this->onlineEnterpriseId;
- //引用dao
- $objDSysAreaChina = new DSysAreaChina(); //省市区dao
- //获取数据
- $postArray = [];
- foreach ($params as $value) {
- $supplierArray = $value;
- //供应商导入信息
- $title = isset($supplierArray['title']) ? trim($supplierArray['title']) : '';//供应商名称
- $realName = isset($supplierArray['realName']) ? trim($supplierArray['realName']) : '';//联系人姓名
- $mobile = isset($supplierArray['mobile']) ? trim($supplierArray['mobile']) : '';//手机号
- $phone = isset($supplierArray['phone']) ? trim($supplierArray['phone']) : 4;//电话
- $position = isset($supplierArray['position']) ? trim($supplierArray['position']) : '';//职务
- $email = isset($supplierArray['email']) ? trim($supplierArray['email']) : '';//邮件
- $remark = isset($supplierArray['remark']) ? trim($supplierArray['remark']) : '';//客户备注
-
- $accountName = isset($supplierArray['accountName']) ? trim($supplierArray['accountName']) : '';//户名
- $bankName = isset($supplierArray['bankName']) ? trim($supplierArray['bankName']) : '';//开户行
- $bankCard = isset($supplierArray['bankCard']) ? trim($supplierArray['bankCard']) : '';//银行卡号
- //省市区
- $provinceName = isset($supplierArray['provinceName']) ? trim($supplierArray['provinceName']) : '';//省名称
- $cityName = isset($supplierArray['cityName']) ? trim($supplierArray['cityName']) : '';//市名称
- $areaName = isset($supplierArray['areaName']) ? trim($supplierArray['areaName']) : '';//区名称
- $address = isset($supplierArray['address']) ? trim($supplierArray['address']) : '';//详细地址
-
- if (empty($title)) {
- continue;
- }
-
- //省市区
- $provinceCode ='';
- $cityCode = '';
- $areaCode = '';
- if(!empty($provinceName)){
- //省编码
- $dbResult = $objDSysAreaChina->get(['name'=>$provinceName]);
- if($dbResult !== false){
- $provinceCode = $dbResult['code'];
- //市编码
- $dbResult = $objDSysAreaChina->get(['name'=>$cityName,'pcode'=>$provinceCode]);
- if($dbResult !== false){
- $cityCode = $dbResult['code'];
- //区编码
- $dbResult = $objDSysAreaChina->get(['name'=>$areaName,'pcode'=>$cityCode]);
- if($dbResult !== false){
- $areaCode = $dbResult['code'];
- }
- }
- }
-
- }
- $enableStatus = 5;
- $postData = array(
- 'title' => $title,
- 'provinceCode' => $provinceCode,
- 'cityCode' => $cityCode,
- 'districtCode' => $areaCode,
- 'address' => $address,
- 'realName' => $realName,
- 'mobile' => $mobile,
- 'enableStatus' => $enableStatus,
- 'sex' => 0,
- 'phone' => $phone,
- 'position' => $position,
- 'email' => $email,
- 'remark' => $remark,
- 'accountName' => $accountName,
- 'bankName' => $bankName,
- 'bankCard' => $bankCard,
- );
- $postArray[] = $postData;
- }
- return $postArray;
- }
-
- /**
- * 导入供应商
- * @throws \Exception
- */
- public function supplierImport()
- {
- //把页面传来的参数对应到符合的字段中全部传递过来;
- $paramsArray = self::getSupplierBasicImportParams();
- if (empty($paramsArray)) {
- $this->sendOutput('参数为空', ErrorCode::$paramError);
- }
-
- $supplierBasic = [];
- foreach ($paramsArray as $params){
- $supplierBasicData = [
- 'title' => isset($params['title']) ? $params['title'] : '',
- 'provinceCode' => isset($params['provinceCode']) ? $params['provinceCode'] : '',
- 'cityCode' => isset($params['cityCode']) ? $params['cityCode'] : '',
- 'realName' => isset($params['realName']) ? $params['realName'] : '',
- 'enableStatus' => isset($params['enableStatus']) ? $params['enableStatus'] : '',
- ];
- foreach ($supplierBasicData as $key => $value) {
- if (empty($value) && $value !== 0) {
- $this->sendOutput($key . '参数错误', ErrorCode::$paramError);
- }
- }
- $supplierBasicData['districtCode'] = isset($params['districtCode']) ? $params['districtCode'] : null;
- $supplierBasicData['address'] = isset($params['address']) ? $params['address'] : null;
- $supplierBasicData['mobile'] = isset($params['mobile']) ? $params['mobile'] : null;
- $supplierBasicData['sex'] = isset($params['sex']) ? $params['sex'] : null;
- $supplierBasicData['phone'] = isset($params['phone']) ? $params['phone'] : null;
- $supplierBasicData['position'] = isset($params['position']) ? $params['position'] : null;
- $supplierBasicData['email'] = isset($params['email']) ? $params['email'] : null;
- $supplierBasicData['remark'] = isset($params['remark']) ? $params['remark'] : null;
- $supplierBasicData['accountName'] = isset($params['accountName']) ? $params['accountName'] : null;
- $supplierBasicData['bankName'] = isset($params['bankName']) ? $params['bankName'] : null;
- $supplierBasicData['bankCard'] = isset($params['bankCard']) ? $params['bankCard'] : null;
- $supplierBasic[] = $supplierBasicData;
- }
- unset($supplierBasicData);
- $total = 0;
- $true = 0;
- $false = 0;
- foreach ($supplierBasic as $key => $supplierBasicData){
- $result = $this->objMSupplier->addSupplier($supplierBasicData);
- if(!$result->isSuccess()){
- $false++;
- } else {
- $true++;
- }
- $total++;
- }
- $return = "共导入'$total'条数据,成功'$true'条数据,失败'$false'条数据";
- parent::sendOutput($return);
- }
-
- }
|