onlineEnterpriseId = $onlineEnterpriseId; $this->onlineUserId = $onlineUserId; $this->objDReceiptTemplate = new DReceiptTemplate(); $this->objDAdminSetting = new DAdminSetting(); self::init(); } /** * Doc: (des="") * User: XMing * Date: 2020/8/26 * Time: 9:51 上午 */ public function init() { $adminLists = $this->objDAdminSetting->select( [ 'type' => StatusCode::$adminSettingType['printTemplate'],'signId' => [StatusCode::$orderType['saleOrder'], StatusCode::$orderType['saleOut'],StatusCode::$orderType['saleReturn'],StatusCode::$orderType['purchaseIn']] ], 'content,title,signId' ); if ($adminLists === false){ Logger::logs(E_USER_ERROR,'sql',__CLASS__,__LINE__,$this->objDAdminSetting->error()); return ResultWrapper::fail($this->objDAdminSetting->error(),ErrorCode::$dberror); } if (empty($adminLists)){ return ResultWrapper::success('没有数据需要操作'); } $receiptTemplateLists = $this->objDReceiptTemplate->select(['enterpriseId' => $this->onlineEnterpriseId],'id,receiptType'); if ($receiptTemplateLists === false){ Logger::logs(E_USER_ERROR,'sql',__CLASS__,__LINE__,$this->objDReceiptTemplate->error()); return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } $insert = []; if (empty($receiptTemplateLists)){ foreach ($adminLists as $value){ $insert[] = [ 'enterpriseId' => $this->onlineEnterpriseId, 'title' => $value['title'], 'fieldsData' => $value['content'], 'receiptType' => $value['signId'], 'createTime' => time(), 'operatorName' => '系统' ]; } unset($value); }else{ $map = []; foreach ($receiptTemplateLists as $value){ $map[$value['receiptType']] = $value; } unset($value); foreach ($adminLists as $value){ if (!isset($map[$value['signId']])){ $insert[] = [ 'enterpriseId' => $this->onlineEnterpriseId, 'title' => $value['title'], 'fieldsData' => $value['content'], 'receiptType' => $value['signId'], 'createTime' => time(), 'operatorName' => '系统' ]; } } unset($value); } if (empty($insert)){ return ResultWrapper::success('没有数据需要操作'); } $result = $this->objDReceiptTemplate->insert($insert,true); if ($result === false){ Logger::logs(E_USER_ERROR,'sql',__CLASS__,__LINE__,$this->objDReceiptTemplate->error()); return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } return ResultWrapper::success(true); } /** * Doc: (des="") * User: XMing * Date: 2020/8/26 * Time: 9:51 上午 */ public function getAll() { $list = $this->objDReceiptTemplate->select(['enterpriseId'=>$this->onlineEnterpriseId],'*'); if ($list === false){ return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } foreach ($list as &$value){ $value['printTypeMsg'] = '网页打印'; $value['fieldsData'] = empty($value['fieldsData']) ? $value['fieldsData'] : json_decode($value['fieldsData'],true); } return ResultWrapper::success($list); } /** * Doc: (des="") * User: XMing * Date: 2020/8/26 * Time: 10:39 上午 * @param array $params * @param int $id * @return ResultWrapper */ public function save(array $params,int $id) { $updateResult = $this->objDReceiptTemplate->update($params,['id'=>$id]); if ($updateResult === false){ return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } return ResultWrapper::success('操作成功'); } /** * Doc: (des="") * User: XMing * Date: 2020/8/26 * Time: 11:04 上午 * @param int $id * @return ResultWrapper */ public function getInfo(int $id) { $result = $this->objDReceiptTemplate->get(['id' => $id,'enterpriseId' => $this->onlineEnterpriseId]); if ($result === false){ return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } $result['describe'] = htmlspecialchars_decode($result['describe'],ENT_QUOTES);; if (empty($result['fieldsData'])){ $result['fieldsData'] = []; }else{ $params = json_decode($result['fieldsData'],true); $formatResult = self::formatSort($params,$result['receiptType']); if (!$formatResult->isSuccess()){ return ResultWrapper::fail($formatResult->getData(),$formatResult->getErrorCode()); } $result['fieldsData'] = $formatResult->getData(); } return ResultWrapper::success($result); } private function formatSort(array $params,$type) { $orderMapSort = [ 'basic'=>[ 'enterprise' => 0, 'operatorName' => 1, 'orderNo' => 2, 'createTime' => 3, 'customerName' => 4, 'customerMobile' => 5, 'deliveryType' => 6, 'receivedName' => 7, 'receivedMobile' => 8, 'customerAddress'=> 9, 'remark' => 10, 'printing'=> 11 //是否选择打印标 ], 'goods' => [ 'goodsId'=> 0, 'images'=> 1, 'goodsName' => 2, 'unitName' => 3, 'specName' => 4, 'skuValue' => 5, 'buyNum' => 6, 'unitPrice' => 7, 'totalPrice' => 8, 'barCode' => 9, 'reservoirArea'=> 10, 'location'=>11 ], 'fiance' => [ 'accountName'=>0, 'receivable' => 1, 'orderPreferential' => 2, 'netReceipts' => 3, 'currentShortage'=> 4, 'upOwe' => 5, 'totalDeficit' => 6 ], 'other'=>[ 'shopName'=>0, 'shopMobile'=>1, 'shopAddress'=>2, 'shopDescribe'=>3, 'signature'=>4, 'printingNum'=>5 ], ]; $outMapSort = [ 'basic' => [ 'enterprise' => 0, 'operatorName' => 1, 'orderNo' => 2, 'createTime' => 3, 'customerName' => 4, 'customerMobile' => 5, 'deliveryType' => 6, 'receivedName' => 7, 'receivedMobile' => 8, 'customerAddress'=> 9, 'remark' => 10 ], 'goods' => [ 'goodsId' => 0, 'images'=> 1, 'goodsName' => 2, 'unitName' => 3, 'specName' => 4, 'skuValue' => 5, 'buyNum' => 6, 'outNum' => 7, 'unitPrice' => 8, 'originTotalPrice' => 9, 'totalPrice' => 10, 'strageCode' => 11, 'barCode' => 12, 'reservoirArea'=> 13, 'location'=>14 ], 'other'=>[ 'shopName'=>0, 'shopMobile'=>1, 'shopAddress'=>2, 'shopDescribe'=>3, 'signature'=>4, 'printingNum'=>5 ], 'fiance' => [ ], ]; $data = $params['templateInfo']; switch ($type){ case StatusCode::$orderType['saleOrder']: $allMap = []; foreach ($data as $key => $row){ if (!isset($orderMapSort[$key])){ return ResultWrapper::fail('格式化打印模版错误',ErrorCode::$paramError); } $sortMap = $orderMapSort[$key]; $nowMap = []; foreach ($row as $item){ $alias = $item['alias']; $nowMap[$sortMap[$alias]] = $item; } ksort($nowMap); $allMap[$key] = array_values($nowMap); } $params['templateInfo'] = $allMap; break; case StatusCode::$orderType['saleOut']: $allMap = []; foreach ($data as $key => $row){ if (!isset($outMapSort[$key])){ return ResultWrapper::fail('格式化打印模版错误',ErrorCode::$paramError); } $sortMap = $outMapSort[$key]; $nowMap = []; foreach ($row as $item){ $alias = $item['alias']; $nowMap[$sortMap[$alias]] = $item; } ksort($nowMap); $allMap[$key] = array_values($nowMap); } $params['templateInfo'] = $allMap; break; } return ResultWrapper::success($params); } /** * Doc: (des="获取对应类型模版") * User: XMing * Date: 2020/8/29 * Time: 4:51 下午 * @param int $id * @return ResultWrapper */ public function getTemplateInfo(int $id) { $result = $this->objDReceiptTemplate->get(['receiptType'=>$id,'enterpriseId'=>$this->onlineEnterpriseId]); if ($result === false){ return ResultWrapper::fail($this->objDReceiptTemplate->error(),ErrorCode::$dberror); } $result['describe'] = empty($result['describe'])?"": htmlspecialchars_decode($result['describe'],ENT_QUOTES); if (empty($result['fieldsData'])){ $result['fieldsData'] = []; }else{ $result['fieldsData'] = json_decode($result['fieldsData'],true); } return ResultWrapper::success($result); } }