feat.例行push
This commit is contained in:
parent
75cc5c95e7
commit
2b8c5be3d1
@ -23,23 +23,25 @@ public function index()
|
|||||||
*/
|
*/
|
||||||
public function create(Request $request)
|
public function create(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$user_id = Auth::guard('member')->user()->id;
|
$user_id = Auth::guard('member')->user()->id;
|
||||||
$count = Promocode::where('used_count', $user_id)->count();
|
$count = Promocode::where('used_count', $user_id)->count();
|
||||||
$give_to = $request->input('give_to');
|
$give_to = $request->input('give_to');
|
||||||
$from = $request->input('from');
|
$from = $request->input('from');
|
||||||
$row = Promocode::where('used_count', 0)
|
$row = Promocode::where('used_count', 0)
|
||||||
->where('from', $from)
|
->where('from', $from)
|
||||||
->where(
|
|
||||||
'valid_from',
|
|
||||||
'<=',
|
|
||||||
now()
|
|
||||||
)->where('valid_to', '>=', now())
|
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (!$row) {
|
||||||
|
return response()->json(['status' => 'error', 'msg' => '目前無可用的優惠碼']);
|
||||||
|
}
|
||||||
|
|
||||||
$row->used_count = $user_id;
|
$row->used_count = $user_id;
|
||||||
$row->give_to = $give_to;
|
$row->give_to = $give_to;
|
||||||
$row->save();
|
$row->save();
|
||||||
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code, 'give_to' => $row->give_to]);
|
return response()->json(['status' => 'success', 'msg' => '已成功取得', 'promocode' => $row->code, 'give_to' => $row->give_to]);
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Summary of morePromocode
|
* Summary of morePromocode
|
||||||
|
|||||||
@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
class Member extends Authenticatable
|
class Member extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasApiTokens, Notifiable;
|
use HasApiTokens;
|
||||||
|
use Notifiable;
|
||||||
|
|
||||||
protected $table = 'members';
|
protected $table = 'members';
|
||||||
/**
|
/**
|
||||||
@ -64,7 +65,7 @@ public function getLevelNameAttribute()
|
|||||||
|
|
||||||
public function getPromoCode()
|
public function getPromoCode()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Promocode::class, 'used_count', 'id');
|
return $this->hasMany(Promocode::class, 'giveto_mem_id', 'id');
|
||||||
}
|
}
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -278,7 +278,7 @@ class='ri-bar-chart-2-line ri-24px text-body me-4'></i>消費紀錄</h5>
|
|||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
console.log("Document is ready");
|
console.log("Document is ready");
|
||||||
var id = "{{ Auth::guard('member')->user()->id }}";
|
var id = "{{ Auth::guard('member')->user()->id }}";
|
||||||
$("#promocode").hide();
|
$("#promocode-show").hide();
|
||||||
$("#promocode-show-teamaster").hide();
|
$("#promocode-show-teamaster").hide();
|
||||||
$("#tea-give-to").hide();
|
$("#tea-give-to").hide();
|
||||||
// 建立 QR Code
|
// 建立 QR Code
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user