WxGuideRepository.php
2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/2/7
* Time: 18:12
*/
namespace App\Repositories\Backend\WxGuide;
use App\Modules\Models\Machine\Machine;
use Illuminate\Support\Facades\DB;
use App\Modules\Repositories\WxGuide\BaseWxGuideRepository;
class WxGuideRepository extends BaseWxGuideRepository
{
public function getForDataTable()
{
return $this->query()->get();
}
public function getinfo()
{
return $this->query()->select('wx_guide.id', 'wx_guide.expire_time', 'wx_guide.bonus', 'wx_guide.number', 'wx_guide.qrcode', 'wx_guide.created_at as ctime', 'spot.spotname', 'business.business_name', 'coupon_type.type', 'coupon_type.discount', 'coupon_type.discount_money', 'coupon_type.reason', 'customers.nick_name')
->leftjoin('spot', 'wx_guide.spot_id', '=', 'spot.id')
->leftjoin('business', 'wx_guide.business_id', '=', 'business.id')
->leftjoin('coupon_type', 'wx_guide.coupon_type_id', '=', 'coupon_type.id')
->leftjoin('customers', 'wx_guide.user_id', '=', 'customers.id')
->get();
}
protected function createUserStub($info)
{
$wxguide = self::MODEL;
$wxguide = new $wxguide;
$wxguide->business_id = $info['business_id'];
$wxguide->spot_id = $info['spot_id'];
// $wxguide->number = $info['number'];
$wxguide->expire_time = $info['expire_time'];
$wxguide->qrcode = $this->createqrcode();
$wxguide->old = 0;
$wxguide->coupon_type_id = $info['coupon_type_id'];
$wxguide->bonus = $info['bonus'] * 100;
return $wxguide;
}
//生成唯一标签
public function createqrcode()
{
$yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
return $orderSn = $yCode[intval(date('Y')) - 2011] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
}
public function create($input)
{
$info = $input['data'];
$wxguide = $this->createUserStub($info);
DB::transaction(function () use ($wxguide, $info) {
if ($wxguide->save()) {
//event(new Explain_infoCreated($wxguide));
return true;
}
throw new GeneralException(trans('exceptions.backend.wxguide.create_error'));
});
}
}