MOrderReceive.Class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. /**
  3. * 订单收货信息数据模型
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/1
  7. * Time: 13:53
  8. */
  9. namespace JinDouYun\Model\Order;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use JinDouYun\Dao\Order\DOrderReceive;
  13. use Mall\Framework\Core\StatusCode;
  14. class MOrderReceive
  15. {
  16. private $objDOrderReceive;
  17. private $cutTable = 200000;
  18. private $onlineUserId;
  19. private $onlineEnterpriseId;
  20. /**
  21. * MOrderReceive constructor.
  22. * @param $onlineUserId
  23. * @param $onlineEnterpriseId
  24. * @throws \Exception
  25. */
  26. public function __construct($onlineUserId, $onlineEnterpriseId)
  27. {
  28. $this->onlineUserId = $onlineUserId;
  29. $this->onlineEnterpriseId = $onlineEnterpriseId;
  30. $this->objDOrderReceive = new DOrderReceive('default');
  31. self::orderReceiveSubTable($onlineEnterpriseId, $onlineUserId);
  32. }
  33. /**
  34. * 订单收货分表
  35. * @param $enterpriseId (企业id)
  36. * @param $userId (用户id)
  37. * @throws \Exception
  38. */
  39. public function orderReceiveSubTable($enterpriseId, $userId)
  40. {
  41. $tableName = $this->objDOrderReceive->getTableName($this->objDOrderReceive->get_Table() . '_' . $enterpriseId, $userId, $this->cutTable);
  42. $this->objDOrderReceive->setTable($tableName);
  43. }
  44. /**
  45. * 添加订单收货信息
  46. * @param $params
  47. * @return ResultWrapper
  48. * @throws \Exception
  49. */
  50. public function addOrderReceive($params)
  51. {
  52. $dbResult = $this->objDOrderReceive->insert($params);
  53. if ($dbResult === false) {
  54. return ResultWrapper::fail($this->objDOrderReceive->error(), ErrorCode::$dberror);
  55. } else {
  56. return ResultWrapper::success($dbResult);
  57. }
  58. }
  59. /**
  60. * 通过订单id,获取订单收货信息
  61. * @param $selectParams ['orderId'=>[1,2,3]]
  62. * @return ResultWrapper
  63. */
  64. public function getOrderReceiveByOrderIds($selectParams)
  65. {
  66. $dbResult = $this->objDOrderReceive->select($selectParams, 'id,orderId,customerId,address,realName,mobile,cityCode,districtCode,provinceCode');
  67. if ($dbResult === false) {
  68. return ResultWrapper::fail($this->objDOrderReceive->error(), ErrorCode::$dberror);
  69. } else {
  70. return ResultWrapper::success($dbResult);
  71. }
  72. }
  73. /**
  74. * 更新收货数据
  75. *
  76. * @param $data
  77. * @param $where
  78. * @return ResultWrapper
  79. */
  80. public function updateReceive($data, $where)
  81. {
  82. $dbResult = $this->objDOrderReceive->update($data, $where);
  83. if ($dbResult === false) {
  84. return ResultWrapper::fail($this->objDOrderReceive->error(), ErrorCode::$dberror);
  85. } else {
  86. return ResultWrapper::success($dbResult);
  87. }
  88. }
  89. /**
  90. * Doc: (des="订单收货地址数据")
  91. * User: XMing
  92. * Date: 2020/11/4
  93. * Time: 10:04 上午
  94. * @param array $params
  95. * @return array
  96. */
  97. public static function buildOrderReceive(array $params): array
  98. {
  99. return [
  100. "no" => isset($params['no']) ? $params['no'] : '',
  101. //char(25) NOT NULL COMMENT '订单编号',
  102. "orderId" => isset($params['orderId']) ? $params['orderId'] : 0,
  103. //int(10) NOT NULL DEFAULT '0' COMMENT '订单Id',
  104. "customerId" => isset($params['customerId']) ? $params['customerId'] : 0,
  105. //int(10) NOT NULL DEFAULT '0' COMMENT '客户Id',
  106. "customerCode" => isset($params['customerCode']) ? $params['customerCode'] : '',
  107. //varchar(255) DEFAULT '' COMMENT '客户编码',
  108. "realName" => isset($params['name']) ? $params['name'] : '',
  109. //varchar(255) NOT NULL DEFAULT '' COMMENT '收货人姓名',
  110. "mobile" => isset($params['mobile']) ? $params['mobile'] : '',
  111. //char(11) NOT NULL DEFAULT '' COMMENT '收货人电话',
  112. "address" => isset($params['address']) ? $params['address'] : '',
  113. //varchar(255) NOT NULL DEFAULT '' COMMENT '收货详细地址',
  114. "provinceCode" => isset($params['provinceCode']) ? $params['provinceCode'] : '',
  115. //int(10) DEFAULT '0' COMMENT '省份编码',
  116. "cityCode" => isset($params['cityCode']) ? $params['cityCode'] : '',
  117. //int(10) DEFAULT '0' COMMENT '城市编码',
  118. "districtCode" => isset($params['districtCode']) ? $params['districtCode'] : '',
  119. //int(10) DEFAULT '0' COMMENT '区编码',
  120. "remark" => isset($params['remark']) ? $params['remark'] : '',
  121. //varchar(255) NOT NULL DEFAULT '' COMMENT '收货备注',
  122. "deleteStatus" => StatusCode::$standard,
  123. //tinyint(3) NOT NULL DEFAULT '5' COMMENT '是否删除 默认5 正常 4删除',
  124. "createTime" => time(),
  125. //int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  126. "updateTime" => time(),
  127. //int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
  128. "detailAddress" => isset($params['detailAddress']) ? $params['detailAddress'] : '',
  129. //varchar(255) DEFAULT '' COMMENT '详细收货地址',
  130. ];
  131. }
  132. }