MReceiptAdapter.Class.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. namespace JinDouYun\Model\System;
  3. use JinDouYun\Model\MBaseModel;
  4. use Mall\Framework\Core\StatusCode;
  5. /**
  6. * 数组的转换,封装
  7. * Class MReceiptAdapter
  8. * @package JinDouYun\Model\System
  9. */
  10. class MReceiptAdapter extends MBaseModel
  11. {
  12. public function __construct($onlineEnterpriseId = '', $onlineUserId = '')
  13. {
  14. parent::__construct($onlineEnterpriseId, $onlineUserId);
  15. }
  16. /**
  17. * 对外转换方法
  18. * @param array $data
  19. * @param int $type
  20. * @return null
  21. */
  22. public function arrayToPattern(array $data,int $type)
  23. {
  24. switch ($type){
  25. case StatusCode::$orderType['salesSlip']:
  26. //销售单
  27. return self::saleOrderPattern($data);
  28. break;
  29. case StatusCode::$orderType['saleOrder']:
  30. return self::orderPattern($data);
  31. break;
  32. //TODO
  33. }
  34. }
  35. /**
  36. * 销售单
  37. * @param array $data
  38. * @return string
  39. */
  40. private function saleOrderPattern(array $data)
  41. {
  42. $goods = [];
  43. $goodsDetails = $data['goodsData'];
  44. foreach($goodsDetails as $value){
  45. $goods[$value['goodsId']]['title'] = $value['goodsName'];
  46. $goods[$value['goodsId']]['skuData'][] = [
  47. 'skuName' => empty($value['specGroup']) ? '' : implode('+',array_column($value['specGroup'],'specValueName')),
  48. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  49. 'unitPrice' => isset($value['price']) ? $value['price'] : 0.00,
  50. 'num' => isset($value['buyNum']) ? $value['buyNum'] : 0,
  51. 'amountPrice' => isset($value['totalMoney']) ? $value['totalMoney'] : 0
  52. ];
  53. }
  54. $printData = [
  55. 'title' => '销售单',
  56. 'codeName' => '单号',
  57. 'code' => $data['no'],
  58. 'createTime' => $data['createTime'],
  59. 'shopName' => $data['shopName'],
  60. 'userName' => $data['customerName'],
  61. 'mobile' => $data['receiveData']['mobile'],
  62. 'preferential' => $data['preferential'], //优惠金额
  63. 'totalMoney' => $data['totalMoney'],
  64. 'payAmount' => $data['payAmount'],
  65. 'details' => $goods,
  66. 'address' => $data['receiveData']['address']
  67. ];
  68. return parent::formatMsg($printData);
  69. }
  70. /**
  71. * 订单
  72. * @param array $data
  73. * @return string
  74. */
  75. private function orderPattern(array $data)
  76. {
  77. $goods = [];
  78. $goodsDetails = $data['goodsData'];
  79. foreach($goodsDetails as $value){
  80. $goods[$value['goodsId']]['title'] = $value['goodsName'];
  81. $goods[$value['goodsId']]['skuData'][] = [
  82. 'skuName' => empty($value['specGroup']) ? '' : implode('+',array_column($value['specGroup'],'specValueName')),
  83. 'unitName' => isset($value['unitName']) ? $value['unitName'] : '',
  84. 'unitPrice' => isset($value['price']) ? $value['price'] : 0.00,
  85. 'num' => isset($value['buyNum']) ? $value['buyNum'] : 0,
  86. 'amountPrice' => isset($value['totalMoney']) ? $value['totalMoney'] : 0
  87. ];
  88. }
  89. $printData = [
  90. 'title' => '订单',
  91. 'codeName' => '单号',
  92. 'createTime' => $data['createTime'],
  93. 'shopName' => $data['shopName'],
  94. 'code' => $data['no'],
  95. 'userName' => $data['customerName'],
  96. 'mobile' => $data['receiveData']['mobile'],
  97. 'preferential' => $data['preferential'], //优惠金额
  98. 'totalMoney' => $data['totalMoney'],
  99. 'payAmount' => $data['payAmount'],
  100. 'details' => $goods,
  101. 'address' => $data['receiveData']['address']
  102. ];
  103. return parent::formatMsg($printData);
  104. }
  105. }