serializer->decode($item['coupon']['coupon_data'])->name; } else { $couponName = ""; } return $couponName; } case ScratchModel::TYPE_SCORE: return $item['num'] . '积分'; case ScratchModel::TYPE_GOODS: $goodsId = $item["goods_id"]; if (isset($item["goods"])) { $goods = $item['goods']; } else { $goods = Goods::findOne($goodsId); } if ($status != "start") { $data = ["name" => $goods['goods_name'], "pic" => $goods['cover_pic']]; return $data; } return $goods['goods_name']; case ScratchModel::TYPE_THANKS: return '谢谢参与'; default: return ''; } } public static function getNewName1($mallId, $item, $status = 'start') { $typeList = ScratchModel::getTypeList($mallId); switch ($item['type']) { case ScratchModel::TYPE_REDPACKET: return $item['price'] . '元' . $typeList[ScratchModel::TYPE_REDPACKET]; break; case ScratchModel::TYPE_BALANCE: return $item['balance'] . '元' . $typeList[ScratchModel::TYPE_BALANCE]; case ScratchModel::TYPE_COUPON: if ($status == 'start') { return $item['coupon']['name']; } else { if (isset($item['coupon']['coupon_data']) && !empty($item['coupon']['coupon_data'])) { $couponName = \Yii::$app->serializer->decode($item['coupon']['coupon_data'])->name; } else { $couponName = ""; } return $couponName; } case ScratchModel::TYPE_SCORE: return $item['num'] . $typeList[ScratchModel::TYPE_SCORE]; default: return ''; } } /** * 获取商品信息 * @param $item * @return array * @throws \Exception */ public static function getGoodsInfo($item) { $data = []; $goodsId = $item["goods_id"]; $goods = Goods::find()->select(['g.*', 'a.sign_id', 'a.id as attr_id'])->alias('g')->where([ 'g.id' => $goodsId, 'a.is_delete' => 0, 'g.is_delete' => 0, 'g.mall_id' => $mallId ])->with(["goodsWarehouse"])->leftJoin(['a' => GoodsAttr::tableName()], 'a.goods_id = g.id')->asArray()->one(); if (!$goods) { throw new \Exception('数据异常,该条数据不存在'); } $data['attr_list'] = empty($goods["attr_id"]) ? null : (new Goods())->signToAttr($goods['sign_id'], $goods['attr_groups']); $data['attr_id'] = $goods['attr_id']; $data["name"] = $goods['goodsWarehouse']['name']; $data["pic"] = $goods['goodsWarehouse']['cover_pic']; return $data; } /** * 获取配置 * @param string $fields * @return ScratchSetting|null */ public static function getSetting($mallId, $fields = "*") { if (self::$setting) { return self::$setting; } $setting = ScratchSettingModel::find()->where(['mall_id' => $mallId])->select($fields)->one(); if ($setting) { if ($setting->payment_type) { $setting->payment_type = json_decode($setting->payment_type, true); } else { $setting->payment_type = ['online_pay']; } $setting['send_type'] = self::sendType($setting['send_type']); $setting["start_at"] = date("Y-m-d H:i:s", $setting["start_at"]); $setting["end_at"] = date("Y-m-d H:i:s", $setting["end_at"]); } self::$setting = $setting; return $setting; } /** * 兼容4.1.0之前的发货方式 * @desc * * @param null $data * * @return array|int|mixed|string|string[]|null */ public static function sendType($data = null) { if (!$data) { $data = ['express', 'offline']; } elseif (!is_array($data)) { $data = json_decode($data, true); if (!is_array($data)) { if (is_numeric($data)) { if ($data == 2) { $data = ['offline']; } elseif ($data == 1) { $data = ['express']; } else { $data = ['express', 'offline']; } } else { $data = ['express', 'offline']; } } } return $data; } /** * 获取中奖记录 * @param $mallId * @param array $params * @return array * @throws \ErrorException */ public static function getLotteryRecord($mallId, $params = []) { $fields = ["id", "scratch_id", "coupon_id", "user_id", "status", "type", "num", "detail", "price", "order_id", "goods_id", 'raffled_at', 'created_at']; $params = [ 'with' => [ 'user' => function($q){ $q->select('id,nickname,avatar_url'); }, 'goods' => function($q){ $q->select('id,goods_name,price'); }, 'coupon' => function($q){ $q->select('id,name,sub_price'); }, ], 'where' => [ ['=', 'mall_id', $mallId], ], 'select' => $fields, 'page' => $postData['page'] ?? 1, 'limit' => $postData['limit'] ?? 10, 'order' => $postData['order'] ?? 'id desc', ]; if (!empty($postData['type'])) { $params['where'][] = ['=', 'type', $postData['type']]; } else { $params['where'][] = ['in', 'type', [1, 2, 3, 4, 5]]; } $pageData = ScratchLogModel::listPage($params, false); if ($pageData === false) throw new \ErrorException(ScratchModel::getStaticError()); $typeList = ScratchModel::getTypeList($mallId); $returnData["list"] = []; foreach ($pageData['list'] as $item) { $data["name"] = $typeList[$item["type"]]; if ($item["type"] == ScratchModel::TYPE_GOODS) { $data['name'] = $item['goods']['goods_name'] ?? $typeList[$item["type"]]; $data['price'] = $item['goods']['price'] ?? 0; $item["num"] = 1; } if ($item['type'] == ScratchModel::TYPE_COUPON) { $data['name'] = $item['coupon']['name'] ?? $typeList[$item["type"]]; $data['price'] = $item['coupon']['price'] ?? 0; } $data['type'] = $item['type']; $data["price"] = $item["price"]; $data["num"] = $item["num"]; $data["nickname"] = isset($item["user"]) ? $item["user"]["nickname"] : "普通用户"; $data["raffled_at"] = !empty($item["raffled_at"]) ? date("Y-m-d H:i:s", $item["raffled_at"]) : date("Y-m-d H:i:s", $item["created_at"]); $returnData["list"][] = $data; } $returnData["pagination"] = $pageData['pagination']; $returnData["page_count"] = $pageData['page_count']; return $returnData; } }