123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- <?php
- /**
- * Created by PhpStorm.
- * User: kang
- * Date: 2021/3/8
- * Time: 15:05
- */
- namespace JinDouYun\Model\Customer;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\StatusCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Customer\DCustomer;
- use JinDouYun\Dao\Customer\DCustomerDemand;
- class MCustomerDemand
- {
- private $objDCustomerDemand;
- private $enterpriseId;
- private $userCenterId;
- private $objDCustomer;
-
- public function __construct($enterpriseId, $userCenterId)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
-
- $this->objDCustomerDemand = new DCustomerDemand('default');
- $this->objDCustomer = new DCustomer();
- $this->objDCustomer->setTable('qianniao_customer_'.$enterpriseId);
- }
-
- /**
- * 添加客户需求
- * @param $params
- * @return ResultWrapper
- * @throws Exception
- */
- public function addCustomerdemand($demandData)
- {
- $demandData = $this->objDCustomerDemand->insert($demandData);
- if($demandData === false){
- return ResultWrapper::fail($this->objDCustomerDemand->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($demandData);
- }
-
- /**
- * 获取所有的客户需求提报
- */
- public function getAllCustomerdemand($selectParams)
- {
- $limit = $selectParams['limit'];
- unset($selectParams['limit']);
- $offset = $selectParams['offset'];
- unset($selectParams['offset']);
- $selectParams['deleteStatus'] = StatusCode::$standard;
-
- $returnData = [
- 'data' => [],
- 'total' => 0,
- ];
-
- $whereSql = '';
- if (isset($selectParams['beginTime']) && !empty($selectParams['beginTime'])) {
- $where = empty($whereSql) ? '' : ' AND ';
- $whereSql .= $where . ' createTime >=' . $selectParams['beginTime'];
- }
- if (isset($selectParams['endTime']) && !empty($selectParams['endTime'])) {
- $where = empty($whereSql) ? '' : ' AND ';
- $whereSql .= $where . ' createTime <= '. $selectParams['endTime'];
- }
- $where = empty($whereSql) ? '' : ' AND ';
- $whereSql .= $where . 'deleteStatus = ' . StatusCode::$standard.' AND enterpriseId ='.$this->enterpriseId;
- $dbResult = $this->objDCustomerDemand->select($whereSql,'*','createTime desc',$limit,$offset);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDCustomerDemand->error(), ErrorCode::$dberror);
- }
- if(empty($dbResult)){
- return ResultWrapper::success($returnData);
- }
-
- $dbTotalResult = $this->objDCustomerDemand->count($whereSql);
- if ($dbTotalResult === false) {
- return ResultWrapper::fail($this->objDCustomerDemand->error(), ErrorCode::$dberror);
- }
-
- $return = [
- 'data' => $this->format($dbResult),
- 'total' => $dbTotalResult
- ];
- return ResultWrapper::success($return);
- }
-
- /**
- * 格式化
- * @return array
- */
- public function format($data)
- {
- // 映射客户id对应的名字
- $customerIdBindName = [];
- $customerIds = array_column($data, 'customerId');
- $customerData = $this->objDCustomer->select($customerIds, 'id,name');
- if( !empty($customerData) ){
- foreach ($customerData as $key => $value){
- $customerIdBindName[$value['id']] = $value['name'];
- }
- }
-
- foreach ($data as $key => $value){
- $data[$key]['name'] = '';
- if( isset($customerIdBindName[$value['customerId']]) ){
- $data[$key]['name'] = $customerIdBindName[$value['customerId']];
- }
- }
-
- return $data;
- }
-
- /**
- * 获取指定的客户需求提报
- */
- public function getCustomerdemandInfo($receiptRequisitionId)
- {
- $dbResult = $this->objDCustomerDemand->select($receiptRequisitionId);
- if($dbResult === false){
- return ResultWrapper::fail($this->objDCustomerDemand->error(), ErrorCode::$dberror);
- }
- if( empty($dbResult) ){
- return ResultWrapper::success([]);
- }
- $returnData = self::format($dbResult);
- return ResultWrapper::success( array_pop($returnData) );
- }
- }
|