コード例 #1
0
ファイル: OrdersController.php プロジェクト: kukujiabo/linpai
  private function payedBounProcess ($order) {

    $orderBouns = OrderBoun::where('oid', '=', $order->id) 

      ->where('uid', '=', $user->id)

      ->where('success', 'is', 'null')

      ->get();
  
    foreach ($orderBouns as $orderBoun) {

      $orderBoun->success = 1;

      $orderBoun->save();
    
      if ($orderBoun->btype == 0) {
      
        /*
         * 如果是推荐码.
         */
        $friend = User::find($orderBoun->owner_id);

        if (!empty($friend->id)) {
          /*
           * 触发短信
           */
          event(new TriggerSms($friend->mobile, 'friend_use'));

          /*
           * 触发邮件
           */
          event(new TriggerEmail($friend->email, 'friend_use', [ 'friend' => $user->name ]));

        }

        $bCount = OrderBoun::where('bcode', '=', $orderBoun->bcode)

          ->where('rewarded', '=', 0)

          ->where('success', '=', 1)

          ->count();

        if ($bCount >= 1) {

          /*
           * 成功使用次数达到10张,赠送一张优惠券
           */
          Boun::create([
          
            'note' => 30,

            'type' => 1,

            'uid' => $orderBoun->owner_id,
            
            'code' => Boun::generateOrderCode(),

            'active' => 1
          
          ]);
        
          OrderBoun::where('bcode', '=', $orderBoun->bcode)

            ->where('rewarded', '=', 0)

            ->update(['rewarded' => 1]);
        
        }
      
      
      } else {
        
        /*
         * 如果是优惠码.
         */
        Boun::where('code', '=', $orderBoun) 

          ->where('uid', '=', $user->id)

          ->update(['active' => 0]);
      
      }
    
    }
  
  }
コード例 #2
0
 public function getBouns(Request $request)
 {
     $order_code = $request->input('order_code');
     $uid = $request->input('uid');
     $order = Order::where('code', '=', $order_code)->first();
     $bouns = OrderBoun::where('uid', '=', $uid)->where('oid', '=', $order->id)->get();
     if (count($bouns)) {
         $str = "<div class=\"boun_line\">";
         foreach ($bouns as $boun) {
             $str .= $boun->bcode . '&nbsp;&nbsp;';
         }
         $str .= '</div>';
         return $this->successResponse('res', $str);
     } else {
         $str = "<div class=\"boun_line\">没有使用优惠券</div>";
         return $this->successResponse('res', $str);
     }
 }