本文整理匯總了PHP中Money::minus_money_user方法的典型用法代碼示例。如果您正苦於以下問題:PHP Money::minus_money_user方法的具體用法?PHP Money::minus_money_user怎麽用?PHP Money::minus_money_user使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Money
的用法示例。
在下文中一共展示了Money::minus_money_user方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: putActiveAd
public function putActiveAd($ad_id = 0)
{
try {
$data = post();
$default = array('ad_id' => '', 'day' => '');
$merge = array_merge($default, $data);
$merge = \DLNLab\Classified\Classes\HelperClassified::trim_value($merge);
extract($merge);
if (intval($ad_id) || intval($day)) {
return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'not_valid')), 500);
}
// Get user_id
$user = Auth::getUser();
$user_id = $user->id;
// Check user money
$user_money = Money::get_user_charge_money($user_id);
$money = AdActive::calc_money($day);
if ($user_money - $money < 0) {
// No active ad when user not enough money
return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_enough_money')), 500);
}
// Get Ad
$ad = Ad::whereRaw('id = ? AND user_id = ? AND status != ?', array($id, $user_id, 0))->first();
if (empty($ad)) {
return Response::json(array('status' => 'error', 'message' => trans(CLF_LANG_MESSAGE . 'user_not_perm')), 500);
}
DB::beginTransaction();
try {
// Minus money
$o_money = Money::minus_money_user($user_id, $money);
// Active ad
$ad->status = 1;
$ad->published_at = time();
$ad->save();
// Update add has activated to DB
$now = \Carbon\Carbon::now();
$record = new self();
$record->ad_id = $ad_id;
$record->money = $money;
$record->start_date = $now->toDateTimeString();
$record->end_date = $now->addDays($day)->toDateTimeString();
$record->status = 1;
$record->save();
$user->money_spent = $user->money_spent + $money;
$user->save();
} catch (Exception $ex) {
DB::rollback();
return $ex->getMessage();
}
DB::commit();
return true;
$message = AdActive::active_ad($data, null, $user_id);
$message = $message ? $message : 'fail';
} catch (Exception $ex) {
$code = 403;
$message = $ex->getMessage();
}
return Response::json(response_message($code, $message), $code);
}