$id], [], $page, $size, function ($q) use ($keyword) { if (!empty($keyword)) { return $q::hasWhere('account', function ($q) use ($keyword) { $q->where('nick_name', 'like', "%" . $keyword . "%")->field("nick_name,avatar_url"); }); } else { return $q->with(["account" => function ($query) { $query->field("nick_name,avatar_url"); }]); } }, ["id" => "desc"]); } /** * 获取优惠卷类型 * * @param array $fields * @param array $order * @return Collection */ public function getCouponTypeAll(array $fields = [], array $order = ["id" => "desc"]) { try { return CouponType::order($order)->field($fields)->select(); } catch (\Exception $e) { return new Collection(); } } /** * 发布优惠券 扣除商家余额 * @param $data * @param $totalMoney */ public function releaseCouponMain($data, $totalMoney) { CouponMain::create($data); Business::where("code", $data["business_code"])->dec("balance", $totalMoney)->update(); } /** * 查询商家发布的优惠卷列表 * * @param array $where * @param array $fields * @param int $page * @param int $size * @param callable|null $call * @param array $sortOrder * @return array * @throws Exception */ public function findCouponMainList(array $where, array $fields = [], int $page=1, int $size = 0, callable $call=null, array $sortOrder= []): array { return CouponMain::findList($where, $fields, $page, $size, $call, $sortOrder); } }