alias('v') ->join('ls_retail_mcoupon as m on m.id=v.' . $this::MCOUPON_ID) ->field($fields) ->where($map) ->find(); if (!empty($coupon)) { if ($coupon[$this::CAN_USE_STORE_IDS] != 0) { //限制了使用门店 $canUseStore = explode(',', trim($coupon[$this::CAN_USE_STORE_IDS], ',')); if (!in_array($store_id, $canUseStore)) { $res['status'] = 0; $res['msg'] = '该优惠券不能在当前门店使用'; return $res; } } if (!is_numeric($coupon[$this::NEED_MONEY])) { $res['status'] = 0; $res['msg'] = '优惠券设置有误'; return $res; } $res['status'] = 1; $res['coupon'] = $coupon; $res['msg'] = '查询成功'; return $res; } else { $res['status'] = 0; $res['msg'] = '优惠券信息有误'; return $res; } } /** * 获取多条可使用的优惠券 * @param $map * @param $store_id * @param $fields * @return mixed */ public function getSelectUseCoupon($map, $store_id, $fields = null) { $MCouponModel = D('RetailMCoupon'); if (empty($fields)) { $fields = array( 'v.' . $this::ID, 'v.' . $this::NEED_MONEY . ' as need_money', 'v.' . $this::REDUCE_MONEY . ' as reduce_money', 'v.' . $this::START_TIME, 'v.' . $this::END_TIME, 'v.' . $this::CAN_USE_STORE_IDS, 'm.' . $MCouponModel::COUPON_NAME . ' as coupon_name', ); } $coupon = $this->alias('v') ->join('ls_retail_mcoupon as m on m.id=v.' . $this::MCOUPON_ID) ->field($fields) ->where($map) ->select(); if (!empty($coupon)) { $temp = array(); foreach ($coupon as &$value) { $value['coupon_choice_type'] = 2;//商户优惠券 $value['begin_time'] = date('Y-m-d', $value[$this::START_TIME]); $value['end_time'] = date('Y-m-d', $value[$this::END_TIME]); $value['reducemoney'] = round($value['reducemoney'], 2); $value['needmoney'] = round($value['needmoney'], 2); if ($value[$this::CAN_USE_STORE_IDS] != 0) { //限制了使用门店 $canUseStore = explode(',', trim($value[$this::CAN_USE_STORE_IDS], ',')); if (in_array($store_id, $canUseStore)) { $temp[] = $value; } } else { $temp[] = $value; } } if (!empty($temp)) { return $temp; } else { return false; } } else { return false; } } //发放记录 public function getGrantRecord($where, $fields, $order, $page, $limit) { $list = $this->alias('r') ->join('ls_retail_mcoupon as c on c.id=r.mcouponid') ->join('ls_retail_vip as v on r.vid=v.id') ->field($fields) ->where($where) ->order($order) ->page($page, $limit) ->select(); return $list; } //发放记录 public function getGrantRecordCount($where) { $count = $this->alias('r') ->join('ls_retail_mcoupon as c on c.id=r.mcouponid') ->join('ls_retail_vip as v on r.vid=v.id') ->where($where) ->count(); return $count; } /** * 会员优惠券记录 * @param $where * @param $fields * @param $order * @param $page * @param $limit * @return mixed */ public function getVipCouponList($where, $fields, $order = 'c.id desc', $page = '', $limit = '') { if (!empty($page) && !empty($limit)) { $list = $this->alias('r') ->join('ls_retail_mcoupon as c on r.mcouponid=c.id') ->field($fields) ->where($where) ->order($order) ->page($page, $limit) ->select(); } else { $list = $this->alias('r') ->join('ls_retail_mcoupon as c on r.mcouponid=c.id') ->field($fields) ->where($where) ->order($order) ->select(); } return $list; } /** * 获取单张优惠券 * @param $where * @param $fields * @return mixed */ public function getSingleCoupon($where, $fields) { $coupon = $this->alias('r') ->join('ls_retail_mcoupon as c on c.id=r.mcouponid') ->field($fields) ->where($where) ->find(); return $coupon; } }