Esempio n. 1
0
 /**
  * 关注操作
  */
 private function subscribe()
 {
     //是否扫码关注
     if ($this->qrcode_key) {
         $result = \Model_MemberRecommendRelation::addRelation($this->qrcode_key, $this->wechat->user_id, 2);
     }
 }
Esempio n. 2
0
 /**
  * 添加推荐关系
  *
  * @param $master_id    推荐人用户ID
  * @param $member_id    被推荐人用户ID
  * @param int $depth    关系深度
  * @param string $from  推荐方式
  * @return bool
  * @throws Exception
  */
 public static function addRelation($master_id, $member_id, $depth = 2, $from = 'QRCODE')
 {
     if ($master_id == $member_id) {
         return false;
     }
     //查询被推荐人是否已存在关系库中
     $members = \Model_MemberRecommendRelation::parentMember($member_id);
     if ($members) {
         return false;
     }
     //查询推荐人关系树
     $members = \Model_MemberRecommendRelation::parentMember($master_id);
     //添加一级推荐关系
     $relation = \Model_MemberRecommendRelation::forge(['master_id' => $master_id, 'member_id' => $member_id, 'depth' => 1, 'from' => $from]);
     $relation->save();
     //添加多级推荐关系
     $index = 2;
     foreach ($members as $member) {
         if ($depth < $index) {
             break;
         }
         $data = ['master_id' => $member->master_id, 'member_id' => $member_id, 'depth' => $index, 'from' => $from];
         $relation = \Model_MemberRecommendRelation::forge($data);
         $relation->save();
         $index++;
     }
     return true;
 }
Esempio n. 3
0
File: order.php Progetto: wxl2012/wx
 public function action_cashback_members()
 {
     $params = [];
     $params['items'] = \Model_MemberRecommendRelation::childMembers(\Auth::get_user()->id);
     /*foreach ($members as $member){
           echo "{$member->member_id}[{$member->depth}级]: " . count($member->member->orders) . '单<br>';
           foreach ($member->member->orders as $order) {
               echo '付款金额:' . ($order->original_fee) . '应分总额:' . ($order->original_fee * 0.1 * 0.5);
           }
       }*/
     \View::set_global($params);
     $this->template->content = \View::forge("{$this->theme}/order/members");
 }
Esempio n. 4
0
 /**
  * 订单分红操作
  */
 protected function cashback()
 {
     if (!isset($this->order->seller->auto_cashback) || !$this->order->seller->auto_cashback) {
         $this->result_message = '订单非自动分红操作';
         return false;
     } else {
         if ($this->order->cashback_status) {
             $this->result_message = '请勿重复分红操作';
             return false;
         }
     }
     $rule = \Model_CashbackRule::find($this->order->seller->cashback_default_rule);
     if (!$rule) {
         $this->result_message = '订单分红失败,未找到分红规则';
         return false;
     } else {
         if (!$rule->items) {
             $this->result_message = '未找到具体分红规则明细';
             return false;
         }
     }
     $total_rate = 0;
     $rules = [];
     foreach ($rule->items as $item) {
         $rules[$item->depth] = $item->rate;
         $total_rate += $item->rate;
     }
     if ($total_rate > 100) {
         $this->result_message = '分红规则超出允许的最大比例!';
         return false;
     }
     //待分配金额
     $fee = $this->order->original_fee * ($rule->fee_rate / 100);
     //获取所有待分配会员列表
     $members = \Model_MemberRecommendRelation::parentMember($this->order->buyer_id);
     foreach ($members as $member) {
         //按各级别所得分额分配利润
         $item = \Model_OrderProfitShare::forge(['order_id' => $this->order->id, 'user_id' => $member->master_id, 'member_id' => $member->id, 'total_fee' => $fee * ($rules[$member->depth] / 100)]);
         $item->save();
     }
     $this->order->cashback_status = 1;
     return $this->order->save();
 }
Esempio n. 5
0
File: home.php Progetto: wxl2012/wx
 /**
  * 获取当前用户的推荐人的微信OPENID
  * @return bool
  */
 private function getParentWechatOpenid()
 {
     return 'oqTo9uJao4vdZy5EZH8yQgL_0SY0';
     //获取上级用户
     $members = \Model_MemberRecommendRelation::parentMember(\Auth::get_user()->id);
     if (!$members) {
         return false;
     }
     $member = current($members);
     $to_openid = false;
     //获取上级用户的微信信息
     $wechat = \Model_Wechat::query()->where(['user_id' => $member->master_id])->get_one();
     //获取上级用户的微信OPENID
     foreach ($wechat->ids as $openid) {
         if ($openid->account_id == \Session::get('WXAccount')->id) {
             $to_openid = $openid->openid;
         }
     }
     return $to_openid;
 }