OrderClass.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. namespace bizGhs\order\classes;
  3. use biz\merchant\classes\MerchantAssetClass;
  4. use bizGhs\admin\classes\AdminClass;
  5. use bizGhs\custom\classes\CustomClass;
  6. use bizGhs\stat\classes\StatOrderCountClass;
  7. use common\components\orderSn;
  8. use common\components\stringUtil;
  9. use common\components\util;
  10. use Yii;
  11. use bizGhs\base\classes\BaseClass;
  12. class OrderClass extends BaseClass
  13. {
  14. public static $baseFile = '\bizGhs\order\models\Order';
  15. //已完成
  16. const ORDER_STATUS_COMPLETE = 6;
  17. //已取消
  18. const ORDER_STATUS_CANCEL = 5;
  19. //待通知
  20. const ORDER_STATUS_UN_NOTICE = 4;
  21. //配送中
  22. const ORDER_STATUS_SENDING = 3;
  23. //待配送
  24. const ORDER_STATUS_UN_SEND = 2;
  25. //待付款,待确认
  26. const ORDER_STATUS_UN_PAY = 1;
  27. //未确认配送方式
  28. const SEND_TYPE_UNKNOWN = 1;
  29. //自取,免配送
  30. const SEND_TYPE_NO = 2;
  31. //自己送
  32. const SEND_TYPE_MYSELF = 3;
  33. //快递送,别人送
  34. const SEND_TYPE_OTHER = 4;
  35. //添加订单 shish 2019.12.5
  36. public static function addOrder($data)
  37. {
  38. $date = date("Y-m-d H:i:s");
  39. $merchantId = $data['merchantId'] ?? 0;
  40. $month = date("Ym");
  41. $data['orderSn'] = orderSn::getGhsOrderSn();
  42. $data['payStatus'] = 0;
  43. $data['createTime'] = $date;
  44. $data['addTime'] = time();
  45. //花材列表
  46. $product = $data['product'];
  47. OrderItemClass::batchAdd($product);
  48. //将花店每月的总订单数作为编号
  49. $riseNum = StatOrderCountClass::addOrder($month, $merchantId);
  50. $data['sendNum'] = $riseNum;
  51. $data['num'] = 1;
  52. $data['smallNum'] = 1;
  53. $return = self::add($data);
  54. //全部订单+1,待付款订单+1
  55. $merchantAsset = MerchantAssetClass::getByMerchantId($merchantId, true);
  56. $merchantAsset->unPayOrder += 1;
  57. $merchantAsset->totalOrder += 1;
  58. $merchantAsset->save();
  59. return $return;
  60. }
  61. //根据订单编号查询 shish 2021.19
  62. public static function getByOrderSn($orderSn)
  63. {
  64. return self::getByCondition(['orderSn' => $orderSn]);
  65. }
  66. //订单列表 shish 2021.1.19
  67. public static function getOrderList($where)
  68. {
  69. $data = self::getList('*', $where, 'addTime DESC');
  70. $data['list'] = self::groupOrder($data['list'], true);
  71. $data['allNum'] = 0;
  72. $data['unPayNum'] = 0;
  73. $data['unSendNum'] = 0;
  74. $data['sendingNum'] = 0;
  75. $data['finishNum'] = 0;
  76. return $data;
  77. }
  78. //整合订单员工和供货商等信息 shish 2021.1.19
  79. public static function groupOrder($list, $showButton = false, $showProgress = false, $showProdct = false)
  80. {
  81. if (empty($list)) {
  82. return $list;
  83. }
  84. $customIds = array_unique(array_filter(array_column($list, 'customId')));
  85. $customInfo = CustomClass::getCustomByIds($customIds);
  86. $adminIds = array_unique(array_filter(array_column($list, 'adminId')));
  87. $adminInfo = AdminClass::getAdminByIds($adminIds, null, 'id');
  88. foreach ($list as $key => $val) {
  89. $adminId = $val['adminId'] ?? 0;
  90. $list[$key]['adminName'] = $adminInfo[$adminId]['adminName'] ?? '';
  91. $customId = $val['customId'] ?? 0;
  92. $list[$key]['customName'] = $customInfo[$customId]['name'] ?? '';
  93. $list[$key]['customAvatar'] = $customInfo[$customId]['smallAvatar'] ?? '';
  94. $list[$key]['customMobile'] = $customInfo[$customId]['mobile'] ?? '';
  95. $list[$key]['customAddress'] = $customInfo[$customId]['address'] ?? '';
  96. if ($showButton) {
  97. $list[$key]['buttonList'] = [
  98. ['type' => 'item', 'show' => 1, 'disable' => 1],
  99. ['type' => 'send', 'show' => 1, 'disable' => 0],
  100. ['type' => 'selfGet', 'show' => 1, 'disable' => 0],
  101. ];
  102. }
  103. if ($showProgress) {
  104. $list[$key]['progress'] = [
  105. ['name' => '创建', 'complete' => 1],
  106. ['name' => '待确认', 'complete' => 0],
  107. ['name' => '出库', 'complete' => 0],
  108. ];
  109. }
  110. if ($showProdct) {
  111. $list[$key]['product'] = [
  112. [
  113. 'cover' => 'https://img.huahb.com/uploads/12358/202101/13/0e713d46064ca89b1fb11095b710f244_small.jpeg',
  114. 'name' => '昆明B级红玫瑰卡罗拉', 'property' => 'B级', 'price' => '8.45', 'bigNum' => 2, 'smallNum' => 10
  115. ],
  116. ];
  117. }
  118. }
  119. return $list;
  120. }
  121. public static function valid($info, $shopId)
  122. {
  123. if (isset($info['shopId']) && $info['shopId'] == $shopId) {
  124. return true;
  125. }
  126. util::fail('没有权限操作的订单');
  127. }
  128. //获取订单详情 shish 2021.1.21
  129. public static function getOrderInfo($id)
  130. {
  131. $info = self::getById($id);
  132. $respond = self::groupOrder([$info], true, true, true);
  133. return current($respond);
  134. }
  135. }