123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace JinDouYun\Model\System;
- use JinDouYun\Model\MBaseModel;
- use Mall\Framework\Core\StatusCode;
- /**
- * 数组的转换,封装
- * Class MReceiptAdapter
- * @package JinDouYun\Model\System
- */
- class MReceiptAdapter extends MBaseModel
- {
- public function __construct($onlineEnterpriseId = '', $onlineUserId = '')
- {
- parent::__construct($onlineEnterpriseId, $onlineUserId);
- }
- /**
- * 对外转换方法
- * @param array $data
- * @param int $type
- * @return null
- */
- public function arrayToPattern(array $data,int $type)
- {
- switch ($type){
- case StatusCode::$orderType['salesSlip']:
- //销售单
- return self::saleOrderPattern($data);
- break;
- case StatusCode::$orderType['saleOrder']:
- return self::orderPattern($data);
- break;
- //TODO
- }
- }
- /**
- * 销售单
- * @param array $data
- * @return string
- */
- private function saleOrderPattern(array $data)
- {
- $goods = [];
- $goodsDetails = $data['goodsData'];
- foreach($goodsDetails as $value){
- $goods[$value['goodsId']]['title'] = $value['goodsName'];
- $goods[$value['goodsId']]['skuData'][] = [
- 'skuName' => empty($value['specGroup']) ? '' : implode('+',array_column($value['specGroup'],'specValueName')),
- 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
- 'unitPrice' => isset($value['price']) ? $value['price'] : 0.00,
- 'num' => isset($value['buyNum']) ? $value['buyNum'] : 0,
- 'amountPrice' => isset($value['totalMoney']) ? $value['totalMoney'] : 0
- ];
- }
- $printData = [
- 'title' => '销售单',
- 'codeName' => '单号',
- 'code' => $data['no'],
- 'createTime' => $data['createTime'],
- 'shopName' => $data['shopName'],
- 'userName' => $data['customerName'],
- 'mobile' => $data['receiveData']['mobile'],
- 'preferential' => $data['preferential'], //优惠金额
- 'totalMoney' => $data['totalMoney'],
- 'payAmount' => $data['payAmount'],
- 'details' => $goods,
- 'address' => $data['receiveData']['address']
- ];
- return parent::formatMsg($printData);
- }
- /**
- * 订单
- * @param array $data
- * @return string
- */
- private function orderPattern(array $data)
- {
- $goods = [];
- $goodsDetails = $data['goodsData'];
- foreach($goodsDetails as $value){
- $goods[$value['goodsId']]['title'] = $value['goodsName'];
- $goods[$value['goodsId']]['skuData'][] = [
- 'skuName' => empty($value['specGroup']) ? '' : implode('+',array_column($value['specGroup'],'specValueName')),
- 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
- 'unitPrice' => isset($value['price']) ? $value['price'] : 0.00,
- 'num' => isset($value['buyNum']) ? $value['buyNum'] : 0,
- 'amountPrice' => isset($value['totalMoney']) ? $value['totalMoney'] : 0
- ];
- }
- $printData = [
- 'title' => '订单',
- 'codeName' => '单号',
- 'createTime' => $data['createTime'],
- 'shopName' => $data['shopName'],
- 'code' => $data['no'],
- 'userName' => $data['customerName'],
- 'mobile' => $data['receiveData']['mobile'],
- 'preferential' => $data['preferential'], //优惠金额
- 'totalMoney' => $data['totalMoney'],
- 'payAmount' => $data['payAmount'],
- 'details' => $goods,
- 'address' => $data['receiveData']['address']
- ];
- return parent::formatMsg($printData);
- }
- }
|