OrderClass.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace biz\order\classes;
  3. use common\components\stringUtil;
  4. use common\services\xhOrderDayNumService;
  5. use common\services\xhOrderMonthNumService;
  6. use Yii;
  7. use biz\base\classes\BaseClass;
  8. class OrderClass extends BaseClass
  9. {
  10. public static $baseFile = '\biz\order\models\Order';
  11. //完成
  12. const ORDER_STATUS_COMPLETE = 5;
  13. //已取消
  14. const ORDER_STATUS_CANCEL = 4;
  15. //待通知
  16. const ORDER_STATUS_UN_NOTICE = 3;
  17. //配送中
  18. const ORDER_STATUS_SENDING = 2;
  19. //待配送
  20. const ORDER_STATUS_UN_SEND = 1;
  21. //待付款
  22. const ORDER_STATUS_UN_PAY = 0;
  23. //订单总流程数
  24. const ORDER_TOTAL_FLOW = 5;
  25. //添加订单 shish 2019.12.5
  26. public static function addOrder($data)
  27. {
  28. $date = date("Y-m-d H:i:s");
  29. $merchantId = $data['merchantId'];
  30. $data['orderSn'] = stringUtil::generateOrderNo($merchantId, $data['userId']);
  31. $data['payStatus'] = 0;
  32. $data['createTime'] = $date;
  33. $data['addTime'] = time();
  34. $time = strtotime(date("Y-m-d"));
  35. $year = date("Y");
  36. $month = date("m");
  37. //后面要把下面二个service方法移到class层
  38. //xhOrderDayNumService::addOne($time, $merchantId);
  39. //$monthReturn = xhOrderMonthNumService::addOne($year, $month, $merchantId);
  40. //将花店每月的总订单数作为编号
  41. //$data['sendNum'] = (string)$monthReturn['riseNum'];
  42. $data['sendNum'] = 0;
  43. $return = self::add($data);
  44. return $return;
  45. }
  46. public static function getByOrderSn($orderSn)
  47. {
  48. return self::getByCondition(['orderSn' => $orderSn]);
  49. }
  50. //评价 shish 2019.12.16
  51. public static function comment($data)
  52. {
  53. $id = $data['id'];
  54. unset($data['id']);
  55. return self::updateById($id, $data);
  56. }
  57. //订单
  58. public static function getOrderById($id)
  59. {
  60. $order = self::getById($id);
  61. if (empty($order)) {
  62. return [];
  63. }
  64. $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
  65. return $order;
  66. }
  67. //根据订单查询 shish 2020.1.4
  68. public static function getOrderBySn($orderSn)
  69. {
  70. $order = self::getByCondition(['orderSn' => $orderSn]);
  71. if (empty($order)) {
  72. return [];
  73. }
  74. $id = $order['id'];
  75. $order['goodsInfoList'] = OrderGoodsClass::getGoodsListById($id);
  76. return $order;
  77. }
  78. //返回随机优惠金额 shish 2019.9.12
  79. public static function getRandDiscount($amount)
  80. {
  81. if ($amount <= 0) {
  82. return 0;
  83. }
  84. if ($amount >= 20000) {
  85. $rand = rand(90, 100);
  86. } elseif ($amount > 1000) {
  87. $rand = rand(10, 30);
  88. } elseif ($amount > 500) {
  89. $rand = rand(10, 20);
  90. } elseif ($amount > 260) {
  91. $rand = rand(10, 15);
  92. } elseif ($amount > 100) {
  93. $rand = rand(5, 9);
  94. } elseif ($amount > 50) {
  95. $rand = rand(1, 3);
  96. } elseif ($amount > 10) {
  97. $rand = 1;
  98. } else {
  99. $rand = 0;
  100. }
  101. return $rand / 10;
  102. }
  103. //订单完成 shish 2020.3.12
  104. public static function complete($id)
  105. {
  106. self::updateById($id, ['status' => self::ORDER_STATUS_COMPLETE]);
  107. }
  108. }