123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * AccountMemLikeModel.php UTF-8
- *
- *
- * @date : 2018/6/12 19:51
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huoAccountDeal\model;
- use think\Model;
- use huo\model\member\MemberModel;
- class AccountMemLikeModel extends Model {
- const STATUS_NOT_LIKE = 1;
- const STATUS_LIKED = 2;
- protected $name = 'account_mem_like';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- public function mem() {
- return $this->belongsTo(MemberModel::className(), 'mem_id', 'id');
- }
- public function addData($data) {
- if (empty($data)) {
- return false;
- }
- if ($_obj = self::create($data, true)) {
- return $_obj->id;
- } else {
- return false;
- }
- }
- public function updateData($_data, $am_id) {
- $_map['id'] = $am_id;
- $_rs = self::update($_data, $_map, true);
- if (false == $_rs) {
- return false;
- } else {
- return true;
- }
- }
- /**
- * 根据玩家ID和小号商品ID查询收藏记录
- * @param $mem_id
- * @param $ags_id
- *
- * @return AccountMemLikeModel|null
- * @throws \think\exception\DbException
- */
- public function getByMemIdAndAgsId($mem_id, $ags_id) {
- return self::get(['mem_id' => $mem_id, 'ags_id' => $ags_id]);
- }
- public function isLike($mem_id, $ags_id) {
- $_map['mem_id'] = $mem_id;
- $_map['ags_id'] = $ags_id;
- $_status = $this->where($_map)->value('status');
- if (empty($_status) || self::STATUS_LIKED != $_status) {
- return self::STATUS_NOT_LIKE;
- }
- return self::STATUS_LIKED;
- }
- /**
- * 获取收藏的小号商品数量
- *
- * @param $mem_id
- *
- * @return int|string
- */
- public function getLikeCnt($mem_id) {
- $_map['mem_id'] = $mem_id;
- $_map['status'] = self::STATUS_LIKED;
- $_map['ags_id'] = ['gt', 0];
- return $this->where($_map)->count('distinct(ags_id)');
- }
- }
|