BelongsTo("app\\common\\model\\store\\Store", 'store_id', 'store_id'); } /** * 关联店员表 */ public function clerk() { return $this->BelongsTo("app\\common\\model\\store\\Clerk", 'clerk_id', 'clerk_id'); } /** * 关联用户优惠券表 */ public function usercoupon() { return $this->BelongsTo("app\\common\\model\\plus\\coupon\\UserCoupon", 'user_coupon_id', 'user_coupon_id'); } /** * 关联供应商表 */ public function supplier() { return $this->belongsTo('app\\common\\model\\supplier\\Supplier', 'shop_supplier_id', 'shop_supplier_id')->field(['shop_supplier_id', 'name']); } /** * 新增核销记录 */ public static function add( $user_coupon_id, $project_id, $cost_price, $store_id, $clerk_id, $shop_supplier_id ) { return (new static)->save([ 'user_coupon_id' => $user_coupon_id, 'project_id' => $project_id, 'cost_price' => $cost_price, 'store_id' => $store_id, 'clerk_id' => $clerk_id, 'shop_supplier_id' => $shop_supplier_id, 'app_id' => self::$app_id ]); } /** * 核销优惠券详情 */ public static function detail($where) { $filter = is_array($where) ? $where : ['user_coupon_id' => $where]; return (new static())->where($filter)->find(); } /** * 统计优惠券当天核销数量 */ public static function getVerifyNum($user_coupon_id, $project_id) { $startTime = strtotime(date('Y-m-d')); return (new static())->where('create_time', '>=', $startTime) ->where('create_time', '<', $startTime + 86400) ->where('user_coupon_id', '=', $user_coupon_id) ->where('project_id', '=', $project_id) ->count(); } /** * 统计商户核销的优惠券金额 by yj 2024.3.16 */ public static function getCouponMoneyBySupplier($shop_supplier_id,$create_time='') { $model = new static(); //搜索时间段 if (!empty($create_time)) { $sta_time = array_shift($create_time); $end_time = array_pop($create_time); $model = $model->whereBetweenTime('store_coupon.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } $money = $model->alias("store_coupon") ->join('store', 'store_coupon.store_id = store.store_id', 'left') ->where('store.shop_supplier_id', '=', $shop_supplier_id) ->sum("cost_price"); return $money; } /** * 统计商户核销的优惠券数量 by yj 2024.3.16 */ public static function getCouponNumBySupplier($shop_supplier_id,$create_time='') { $model = new static(); //搜索时间段 if (!empty($create_time)) { $sta_time = array_shift($create_time); $end_time = array_pop($create_time); $model = $model->whereBetweenTime('store_coupon.create_time', $sta_time, date('Y-m-d 23:59:59', strtotime($end_time))); } $num= $model->alias("store_coupon") ->join('store', 'store_coupon.store_id = store.store_id', 'left') ->where('store.shop_supplier_id', '=', $shop_supplier_id) ->count(); return $num; } }