'待审核', 20 => '审核通过', 30 => '驳回', ]; /** * 申请时间 * @param $value * @return false|string */ public function getApplyTimeAttr($value) { return date('Y-m-d H:i:s', $value); } /** * 审核时间 * @param $value * @return false|int|string */ public function getAuditTimeAttr($value) { return $value > 0 ? date('Y-m-d H:i:s', $value) : 0; } /** * 关联推荐人表 * @return \think\model\relation\BelongsTo */ public function referee() { return $this->belongsTo('app\common\model\user\User', 'referee_id') ->field(['user_id', 'nickName']); } /** * 销商申请记录详情 * @param $where * @return array|\think\Model|null * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public static function detail($where) { $filter = is_array($where) ? $where : ['apply_id' => $where]; return (new static())->where($filter)->find(); } /** * 购买指定商品成为分红用户 * @param $userId * @param $productIds * @param $appId * @return bool */ public function becomeBonusUser($userId, $productIds, $appId, $order) { // 验证是否设置 $config = Setting::getItem('basic', $appId); if (empty($config['become__buy_product_ids'])) { return false; } $purchase_count=0; // 每买一个指定商品就生成一个分红订单 foreach ($order['product'] as $product) { // 检查商品是否是指定的分红商品 if (in_array($product['product_id'], $config['become__buy_product_ids'])||$product['is_vip']==1) { // 获取商品数量 $quantity = $product['total_num']; if ($product['is_gift_pack']){ $quantity = $product['total_num']*$product['vip_order_num']; } $purchase_count+=$quantity; // 为每个商品生成分红订单 for ($i = 0; $i < $quantity; $i++) { UserModel::setRepurchaseFrequency($userId); } } } // 判断商品是否在设置范围内 $intersect = array_intersect($productIds, $config['become__buy_product_ids']); if ($purchase_count<=0) { return false; } if(User::isBonusUser($userId)) { return false; } if ($config['purchase_count']>0){ if($purchase_count<$config['purchase_count']){ return false; } } //同时成为分销商 $referee_id = agentReferee::getRefereeUserId($userId, 1); if ($config['become_agent']) { agentUser::add($userId, [ 'referee_id' => $referee_id, 'app_id' => $appId, ]); } // 新增分红用户 User::add($userId, [ 'referee_id' => $referee_id, 'app_id' => $appId, ]); return true; } /** * 审核状态 * @param $value * @return array */ public function getApplyStatusAttr($value) { $method = [10 => '待审核', 20 => '审核通过', '30' => '驳回']; return ['text' => $method[$value], 'value' => $value]; } /** * 审核方式 * @param $value * @return array */ public function getApplyTypeAttr($value) { $method = [10 => '后台审核', 20 => '无需审核']; return ['text' => $method[$value], 'value' => $value]; } }