OrderRepository.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace crmeb\repositories;
  3. use app\models\store\StoreOrder;
  4. use app\models\user\User;
  5. use app\models\user\UserBill;
  6. use app\models\user\WechatUser;
  7. use crmeb\exceptions\AdminException;
  8. use crmeb\services\SystemConfigService;
  9. use think\db\exception\DataNotFoundException;
  10. use think\db\exception\DbException;
  11. use think\db\exception\ModelNotFoundException;
  12. use think\Exception;
  13. /**
  14. * Class OrderRepository
  15. * @package crmeb\repositories
  16. */
  17. class OrderRepository
  18. {
  19. /**
  20. * 用户确认收货
  21. * @param $order
  22. * @param $uid
  23. * @throws Exception
  24. * @throws DataNotFoundException
  25. * @throws ModelNotFoundException
  26. * @throws DbException
  27. * @throws \Exception
  28. */
  29. public static function storeProductOrderUserTakeDelivery($order, $uid)
  30. {
  31. $res1 = StoreOrder::gainUserIntegral($order);
  32. $res2 = User::backOrderBrokerage($order);
  33. StoreOrder::orderTakeAfter($order);
  34. WechatUser::userTakeOrderGiveCoupon($uid, $order['total_price']);//满赠优惠券
  35. UserBill::where('uid', $order['uid'])->where('link_id', $order['id'])->where('type', 'pay_money')->update(['take' => 1]);
  36. if (!($res1 && $res2)) exception('收货失败!');
  37. }
  38. /**
  39. * 修改状态 为已收货 admin模块
  40. * @param $order
  41. * @throws \Exception
  42. */
  43. public static function storeProductOrderTakeDeliveryAdmin($order)
  44. {
  45. $res1 = StoreOrder::gainUserIntegral($order, false);
  46. $res2 = User::backOrderBrokerage($order, false);
  47. StoreOrder::orderTakeAfter($order);
  48. UserBill::where('uid', $order['uid'])->where('link_id', $order['id'])->where('type', 'pay_money')->update(['take' => 1]);
  49. if (!($res1 && $res2)) throw new AdminException('收货失败!');
  50. }
  51. /**
  52. * 修改状态为 已退款 admin模块
  53. * @param $data
  54. * @param $oid
  55. * @return bool|mixed
  56. * @throws DataNotFoundException
  57. * @throws ModelNotFoundException
  58. * @throws DbException
  59. * @throws DbException
  60. */
  61. public static function storeProductOrderRefundY($data, $oid)
  62. {
  63. $order = StoreOrder::where('id', $oid)->find();
  64. if ($order['is_channel'] == 1)
  65. return StoreOrder::refundRoutineTemplate($oid); //TODO 小程序余额退款模板消息
  66. else
  67. return StoreOrder::refundTemplate($data, $oid);//TODO 公众号余额退款模板消息
  68. }
  69. /**
  70. * TODO 后台余额退款
  71. * @param $product
  72. * @param $refund_data
  73. * @throws \Exception
  74. */
  75. public static function storeOrderYueRefund($product, $refund_data)
  76. {
  77. $res = StoreOrder::integralBack($product['id']);
  78. if (!$res) throw new AdminException('退积分失败!');
  79. }
  80. /**
  81. * 订单退积分
  82. * @param $product $product 商品信息
  83. * @param $back_integral $back_integral 退多少积分
  84. */
  85. public static function storeOrderIntegralBack($product, $back_integral)
  86. {
  87. }
  88. public static function computedOrder()
  89. {
  90. }
  91. }