1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- /**
- * 订单优惠数据模型
- * Created by PhpStorm.
- * User: XiaoMing
- * Date: 2019/11/1
- * Time: 13:48
- */
- namespace JinDouYun\Model\Order;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use JinDouYun\Dao\Order\DOrderCoupon;
- class MOrderCoupon
- {
- private $objDOrderCoupon;
- private $cutTable = 200000;
- private $onlineUserId;
- private $onlineEnterpriseId;
- /**
- * MOrderCoupon constructor.
- * @param $onlineUserId
- * @param $onlineEnterpriseId
- * @throws \Exception
- */
- public function __construct($onlineUserId, $onlineEnterpriseId)
- {
- $this->onlineUserId = $onlineUserId;
- $this->onlineEnterpriseId = $onlineEnterpriseId;
- $this->objDOrderCoupon = new DOrderCoupon('default');
- self::orderCouponSubTable($onlineEnterpriseId, $onlineUserId);
- }
- /**
- * 优惠券分表
- * @param $enterpriseId (企业id)
- * @param $userId (用户id)
- * @throws \Exception
- */
- public function orderCouponSubTable($enterpriseId, $userId)
- {
- $tableName = $this->objDOrderCoupon->getTableName($this->objDOrderCoupon->get_Table() . '_' . $enterpriseId, $userId, $this->cutTable);
- $this->objDOrderCoupon->setTable($tableName);
- }
- /**
- * 添加订单优惠信息
- * @param $params
- * @return ResultWrapper
- * @throws \Exception
- */
- public function addOrderCoupon($params,$multiple = false)
- {
- $dbResult = $this->objDOrderCoupon->insert($params, $multiple);
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDOrderCoupon->error(), ErrorCode::$dberror);
- }
- return ResultWrapper::success($dbResult);
- }
- /**
- * 通过订单id,获取订单优惠信息
- * @param $selectParams ['orderId'=>[1,2,3]]
- * @return ResultWrapper
- */
- public function getCouponByOrderIds($selectParams)
- {
- $dbResult = $this->objDOrderCoupon->select($selectParams, '*');
- if ($dbResult === false) {
- return ResultWrapper::fail($this->objDOrderCoupon->error(), ErrorCode::$dberror);
- } else {
- return ResultWrapper::success($dbResult);
- }
- }
- }
|