255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'mall_id' => 'Mall ID', 'user_id' => 'User ID', 'card_id' => 'Card ID', 'name' => '名称', 'pic_url' => '图片', 'content' => '详情', 'is_delete' => '删除', 'created_at' => 'Created At', 'updated_at' => 'Updated At', 'deleted_at' => 'Deleted At', 'is_use' => '是否使用 0--未使用 1--已使用', 'clerk_id' => '核销人id', 'store_id' => '门店ID', 'clerked_at' => ' 核销时间', 'order_id' => '发放卡券的订单id', 'order_detail_id' => '订单详情ID', 'data' => '额外信息字段', 'start_time' => 'Start Time', 'end_time' => 'End Time', 'number' => '核销总次数', 'use_number' => '已核销次数', 'remark' => '备注', 'receive_id' => '转赠领取的用户id', 'parent_card_id' => '转赠的用户卡券id', ]; } public function getClerk() { return $this->hasOne(User::className(), ['id' => 'clerk_id']); } public function getStore() { return $this->hasOne(Store::className(), ['id' => 'store_id']); } public function getCard() { return $this->hasOne(GoodsCards::className(), ['id' => 'card_id']); } public function getUser() { return $this->hasOne(User::className(), ['id' => 'user_id']); } public function getOrder() { return $this->hasOne(Order::className(), ['id' => 'order_id']); } public function getDetail() { return $this->hasOne(OrderDetail::className(), ['id' => 'order_detail_id']); } public function getClerkLog() { return $this->hasMany(GoodsCardClerkLog::className(), ['user_card_id' => 'id']); } public function getLastClerkLog() { return $this->hasOne(GoodsCardClerkLog::className(), ['user_card_id' => 'id'])->orderBy(['clerked_at' => SORT_DESC]); } /** * 兼容旧卡券 * @param UserCard $userCard * @return array; */ public function getNewItem($userCard) { $data = []; if ($userCard->is_use == 1 && $userCard->number - $userCard->use_number > 0) { $data['use_number'] = $userCard->number; } $data['is_show_history'] = 0; if ($userCard->is_use || $userCard->lastClerkLog) { $data['is_show_history'] = 1; } if ($userCard->lastClerkLog) { $data['store_name'] = $userCard->lastClerkLog->store->name; $data['clerked_at'] = new_date($userCard->lastClerkLog->clerked_at); } return $data; } public function getReceive() { return $this->hasOne(User::className(), ['id' => 'receive_id']); } public function getFrom() { return $this->hasOne(User::className(), ['id' => 'user_id']) ->viaTable(UserCard::tableName(), ['id' => 'parent_card_id']); } }