'datetime:Y-m-d h:i:s' ]; protected $fillable = [ 'uniacid', 'member_id', 'type', 'goods_id', 'order_id', 'order_goods_id', 'change_type', 'change_quantity', 'change_front', 'change_after', 'remark', 'created_at', ]; /** * Common: 获取列表 * Author: wu-hui * Time: 2023/09/27 14:04 * @param $pageSize * @param $search * @param string[] $field * @return array */ public function getList($pageSize,$search,$field = ['*']){ // 条件生成 $where = []; if($search['member_id'] > 0) $where[] = ['member_id','=',$search['member_id']]; // if($search['type'] >= 0 && !is_null($search['type'])) $where[] = ['type','=',$search['type']]; if($search['change_type'] >= 0 && !is_null($search['change_type'])) $where[] = ['change_type','=',$search['change_type']]; // 列表获取 $list = self::uniacid() ->select($field) ->where($where) ->with(['member'=>function($query){ $query->select(['uid','nickname','realname','avatar']); }]) ->orderBy('created_at','DESC') ->orderBy('id','DESC') ->paginate($pageSize); return $list ? $list->toArray() : []; } /** * Common: 获取总数 * Author: wu-hui * Time: 2023/09/27 17:49 * @param $uid * @param int $changeType * @return string */ public function getChangeTypeSum($uid,$changeType = -1){ $where = []; if($changeType == 0) $where[] = ['change_type','=',0]; if($changeType == 1) $where[] = ['change_type','=',1]; $sum = (float)self::uniacid()->where('member_id',$uid)->where($where)->sum('change_quantity'); return sprintf("%.2f",$sum); } /** * Common: 权重值增加|减少操作 * Author: wu-hui * Time: 2023/09/27 17:12 * @param int $uid * @param float $money * @param int $changeType * @param string $remark * @param int $type */ public function weightValueOperate(int $uid,float $money,int $changeType = 1,string $remark = '',int $type = 0){ // 获取当前用户持有数量 $changeFront = (float)Member::uniacid()->where('uid',$uid)->value('weight_value'); // 变更后的数量 $changeAfter = $changeType == 1 ? $changeFront + $money : $changeFront - $money; // 变更记录 $data = [ 'uniacid' => \YunShop::app()->uniacid, 'member_id' => $uid,// 用户id 'type' => $type,// 权重值类型:0=经纪人(经销商)权重值 'goods_id' => 0,// 商品id 'order_id' => 0,// 订单id 'order_goods_id' => 0,// 订单商品id 'change_type' => $changeType,// 变更类型:0=减少,1=增加 'change_quantity' => $money,// 变更数量 'change_front' => (float)$changeFront,// 变更前拥有的数量 'change_after' => sprintf("%.2f",$changeAfter),// 变更后拥有的数量 'remark' => $remark,// 备注 'created_at' => time(),// 变更时间 ]; $this->insert($data); // 修改用户持有 Member::uniacid()->where('uid',$uid)->update([ 'weight_value' => $changeAfter ]); } /** * Common: 一对一关联 用户信息 * Author: wu-hui * Time: 2023/09/27 13:43 * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function member(){ return $this->hasOne(Member::class, 'uid', 'member_id'); } }