123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <?php
- namespace app\api\controller\activity;
- use app\admin\model\store\StoreDescription;
- use app\admin\model\store\StoreProductAttrValue;
- use app\models\store\StoreActivity;
- use app\models\store\StoreOrder;
- use app\models\store\StoreProductAttr;
- use app\models\store\StoreProductRelation;
- use app\Request;
- use crmeb\services\QrcodeService;
- use crmeb\services\UtilService;
- use app\models\store\StoreTryProduct as StoreTryProductModel;
- use think\facade\Db;
- use app\models\store\StoreTryRecord as StoreTryRecordModel;
- class StoreTryRecord
- {
-
- public function lst(Request $request)
- {
- list($type, $page, $limit) = UtilService::getMore([
- ['type', 0],
- ['page', 1],
- ['limit', 10],
- ], $request, true);
- $uid = $request->uid();
- $ret = [];
- $list = StoreTryRecordModel::setWherePage(new StoreTryRecordModel(), [], [])->field("tr.*,tp.store_name,tp.image,tp.is_finish,pro.price")->where("tr.uid={$uid} and tr.is_del=0")->alias('tr')->join('store_try_product tp', 'tp.id=tr.tid')->join('store_product pro', 'pro.id=tp.product_id')->page($page, $limit)->select()->each(function ($item) use ($type, &$ret) {
- $item['add_time'] = date('Y-m-d H:i:s', $item['add_time']);
- if ($type == 0) {
- if ($item['is_finish'] == 0) {
- $ret[] = $item;
- }
- } else if ($type == 1) {
- if ($item['is_finish'] == 1 && $item['is_check'] == 1) {
- $ret[] = $item;
- }
- } else {
- if ($item['is_finish'] == 1 && $item['is_check'] == 0) {
- $ret[] = $item;
- }
- }
- })->toArray();
- return app('json')->success('ok', $ret);
- }
-
- public function add(Request $request)
- {
- $param = UtilService::postMore([
- 'tid',
- 'name',
- 'phone',
- 'address',
- 'attr'
- ], $request);
- $uid = $request->uid();
- $time = time();
- if (StoreTryRecordModel::be([
- 'uid' => $uid,
- 'tid' => $param['tid'],
- 'is_del' => 0
- ])) {
- return app('json')->fail('已经申请过,请勿重复申请');
- }
- $tryPro = StoreTryProductModel::where("id={$param['tid']} and is_del=0")->find();
- if (!$tryPro || $tryPro['is_show'] == 0) {
- return app('json')->fail('找不到试用商品或者已经下架');
- }
- if ($tryPro['start_time'] > time()) {
- return app('json')->fail('试用还没开始');
- }
- if ($tryPro['stop_time'] < time()) {
- return app('json')->fail('试用已经结束');
- }
- if ($tryPro['is_finish']) {
- return app('json')->fail('试用已经结束,无法申请');
- }
- StoreTryRecordModel::create([
- 'uid' => $uid,
- 'tid' => $param['tid'],
- 'name' => $param['name'],
- 'phone' => $param['phone'],
- 'address' => $param['address'],
- 'attr' => $param['attr'],
- 'add_time' => $time,
- ]);
- return app('json')->success('试用申请成功');
- }
- }
|