public function censorBooth($id)
 {
     $check = Input::get('check', 0);
     $remark = Input::get('remark', '');
     $interview = Input::get('interview', 0);
     DB::beginTransaction();
     try {
         $booth = Booth::find($id);
         if (empty($booth)) {
             throw new Exception("无法获取到店铺信息", 10001);
         }
         // get fund if there is one
         if ($booth->b_with_fund) {
             $fund = Fund::where('b_id', '=', $id)->first();
             if (empty($fund)) {
                 throw new Exception("基金数据不匹配", 10001);
             }
         } else {
             $fund = false;
         }
         if ($check == 1) {
             if ($booth->b_status == 1) {
                 throw new Exception("店铺已经审核过了", 10002);
             }
             if ($interview != 1) {
                 $booth->b_status = 1;
             }
             if ($fund) {
                 $fund->censorPass($interview);
             }
         } elseif ($check == 0) {
             $booth->b_status = 2;
             $booth->remark = $remark;
             if ($fund) {
                 $fund->censorFailed();
             }
         }
         $booth->censor();
         $re = Tools::reTrue('审核店铺成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '审核店铺失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Esempio n. 2
0
 public function postBooth()
 {
     // base infos
     $token = Input::get('token', '');
     $u_id = Input::get('u_id', '');
     // booth type
     $boothType = Input::get('type');
     // product category
     $productCate = Input::get('prod_cate');
     // booth title
     $boothTitle = Input::get('title');
     // booth position
     $boothLng = Input::get('lng');
     $boothLat = Input::get('lat');
     // product source
     $productSource = Input::get('prod_source');
     // customer group
     $cusomerGroup = Input::get('cust_group');
     // promo strategy
     $promoStratege = Input::get('promo_strategy');
     // with fund
     $withFund = Input::get('fund', 0);
     $booth_cate = Input::get('cate', 0);
     // profit ratio
     $profitRate = Input::get('profit');
     // loan amount
     $loan = Input::get('loan');
     // how to drow loan
     $loanSchema = Input::get('loan_schema', '');
     DB::beginTransaction();
     try {
         $user = User::chkUserByToken($token, $u_id);
         $user->load(['school']);
         $booth = Booth::where('u_id', '=', $u_id)->first();
         if (empty($booth)) {
             $booth = new Booth();
         } else {
             if ($booth->b_status == 1) {
                 throw new Exception("您已经申请过店铺了", 7001);
             }
         }
         $school = $user->school;
         $booth->s_id = $school->t_id;
         $booth->c_id = $school->t_city;
         $booth->pv_id = $school->t_province;
         $booth->u_id = $u_id;
         $booth->b_title = $boothTitle;
         $booth->b_desc = '';
         $booth->latitude = $boothLat;
         $booth->longitude = $boothLng;
         $booth->b_product_source = $productSource;
         $booth->b_product_category = $productCate;
         $booth->b_customer_group = $cusomerGroup;
         $booth->b_promo_strategy = $promoStratege;
         $booth->b_with_fund = $withFund;
         $booth->b_type = $boothType;
         $booth->b_cate = $booth_cate;
         $b_id = $booth->register();
         if ($withFund == 1) {
             $fund = Fund::where('b_id', '=', $booth->b_id)->first();
             if (empty($fund)) {
                 $fund = new Fund();
             } else {
                 if ($fund->t_status > 2) {
                     throw new Exception("基金已经发放", 1);
                 }
             }
             $fund->u_id = $u_id;
             $fund->t_apply_money = $loan;
             $fund->b_id = $b_id;
             $fund->t_profit_rate = $profitRate;
             $f_id = $fund->apply();
             $schema = 0;
             $allotedAmount = 0;
             $loanSchema = json_decode($loanSchema, true);
             if (!is_array($loanSchema)) {
                 throw new Exception("请传入正确的提款计划", 7001);
             }
             // clear all exists schema
             DB::table('repayments')->where('f_id', '=', $f_id)->delete();
             foreach ($loanSchema as $key => $percentage) {
                 $percentage = $percentage / 100;
                 $schema++;
                 if ($schema == count($loanSchema)) {
                     $amount = $loan - $allotedAmount;
                 } else {
                     $amount = $loan * $percentage;
                     $allotedAmount += $amount;
                 }
                 $repayment = new Repayment();
                 $repayment->f_id = $f_id;
                 $repayment->f_re_money = $amount;
                 $repayment->f_schema = $schema;
                 $repayment->f_percentage = $percentage * 100;
                 $repayment->apply();
             }
         } else {
             // if without fund, no need to censor
             $booth->b_status = 1;
             $booth->save();
         }
         $re = Tools::reTrue('申请成功');
         DB::commit();
     } catch (Exception $e) {
         $re = Tools::reFalse($e->getCode(), '申请失败:' . $e->getMessage());
         DB::rollback();
     }
     return Response::json($re);
 }
Esempio n. 3
0
 public function confirm()
 {
     $this->getSummary();
     foreach ($this->_bills as $key => $bill) {
         $booth = Booth::find($key);
         $wallet = UsersWalletBalances::find($booth->u_id);
         if ($booth->b_with_fund) {
             $fund = Fund::where('b_id', '=', $key)->where('t_is_close', '=', 0)->first();
             if (empty($fund)) {
                 $wallet->putIn($bill['total']['paied']);
             }
         } else {
             $wallet->putIn($bill['total']['paied']);
         }
     }
     $this->o_shipping_status = 10;
     return $this->save();
 }
Esempio n. 4
0
 public static function clearByUser($u_id)
 {
     $record = Fund::where('u_id', '=', $u_id)->where('t_status', '=', 0)->first();
     $f_id = 0;
     if (!empty($record)) {
         $f_id = $record->t_id;
         $record->delete();
     }
     return $f_id;
 }