MOrderCoupon.Class.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * 订单优惠数据模型
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/11/1
  7. * Time: 13:48
  8. */
  9. namespace JinDouYun\Model\Order;
  10. use Mall\Framework\Core\ErrorCode;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use JinDouYun\Dao\Order\DOrderCoupon;
  13. class MOrderCoupon
  14. {
  15. private $objDOrderCoupon;
  16. private $cutTable = 200000;
  17. private $onlineUserId;
  18. private $onlineEnterpriseId;
  19. /**
  20. * MOrderCoupon constructor.
  21. * @param $onlineUserId
  22. * @param $onlineEnterpriseId
  23. * @throws \Exception
  24. */
  25. public function __construct($onlineUserId, $onlineEnterpriseId)
  26. {
  27. $this->onlineUserId = $onlineUserId;
  28. $this->onlineEnterpriseId = $onlineEnterpriseId;
  29. $this->objDOrderCoupon = new DOrderCoupon('default');
  30. self::orderCouponSubTable($onlineEnterpriseId, $onlineUserId);
  31. }
  32. /**
  33. * 优惠券分表
  34. * @param $enterpriseId (企业id)
  35. * @param $userId (用户id)
  36. * @throws \Exception
  37. */
  38. public function orderCouponSubTable($enterpriseId, $userId)
  39. {
  40. $tableName = $this->objDOrderCoupon->getTableName($this->objDOrderCoupon->get_Table() . '_' . $enterpriseId, $userId, $this->cutTable);
  41. $this->objDOrderCoupon->setTable($tableName);
  42. }
  43. /**
  44. * 添加订单优惠信息
  45. * @param $params
  46. * @return ResultWrapper
  47. * @throws \Exception
  48. */
  49. public function addOrderCoupon($params,$multiple = false)
  50. {
  51. $dbResult = $this->objDOrderCoupon->insert($params, $multiple);
  52. if ($dbResult === false) {
  53. return ResultWrapper::fail($this->objDOrderCoupon->error(), ErrorCode::$dberror);
  54. }
  55. return ResultWrapper::success($dbResult);
  56. }
  57. /**
  58. * 通过订单id,获取订单优惠信息
  59. * @param $selectParams ['orderId'=>[1,2,3]]
  60. * @return ResultWrapper
  61. */
  62. public function getCouponByOrderIds($selectParams)
  63. {
  64. $dbResult = $this->objDOrderCoupon->select($selectParams, '*');
  65. if ($dbResult === false) {
  66. return ResultWrapper::fail($this->objDOrderCoupon->error(), ErrorCode::$dberror);
  67. } else {
  68. return ResultWrapper::success($dbResult);
  69. }
  70. }
  71. }