diff --git a/models/UserCollect.php b/models/UserCollect.php new file mode 100644 index 0000000..6a5defb --- /dev/null +++ b/models/UserCollect.php @@ -0,0 +1,46 @@ + 'ID', + 'user_id' => 'User ID', + 'goods_id' => 'Goods ID', + ]; + } +} diff --git a/modules/admin/views/store/store-user-edit.php b/modules/admin/views/store/store-user-edit.php index a4a7272..70e494e 100644 --- a/modules/admin/views/store/store-user-edit.php +++ b/modules/admin/views/store/store-user-edit.php @@ -54,7 +54,7 @@ $this->params['breadcrumbs'][] = $this->title;
- $val): ?> @@ -76,7 +76,6 @@ $this->params['breadcrumbs'][] = $this->title;
-
@@ -89,9 +88,6 @@ $this->params['breadcrumbs'][] = $this->title;
- - -
@@ -103,41 +99,43 @@ $this->params['breadcrumbs'][] = $this->title; 'file', + 'multiple' => true, 'id' => 'cover_pic', 'name' => 'cover_pic', 'label' => '封面', 'value' => $model->cover_pic ? $model->cover_pic : '', 'tip' => '建议图片大小650×320', - 'required' => true, + 'required' => false, 'imageCompressEnable' => 1, 'imageCompressBorder' => 750, ]) ?> - 'images', -// 'multiple' => true, -// 'id' => 'pic_urls', -// 'name' => 'pic_urls', -// 'label' => '轮播图', -// 'value' => $model->pic_urls ? $model->pic_urls : '', -// 'tip' => '图片大小750×360', -// 'required' => true, -// 'imageCompressEnable' => 1, -// 'imageCompressBorder' => 750, -// ]) ?> + 'images', + // 'multiple' => true, + // 'id' => 'pic_urls', + // 'name' => 'pic_urls', + // 'label' => '轮播图', + // 'value' => $model->pic_urls ? $model->pic_urls : '', + // 'tip' => '图片大小750×360', + // 'required' => true, + // 'imageCompressEnable' => 1, + // 'imageCompressBorder' => 750, + // ]) ?> - - - - - - -content ? $model->content : "" ?> - - - - + + + + + + + + content ? $model->content : "" ?> + + + +
@@ -179,6 +177,10 @@ $this->params['breadcrumbs'][] = $this->title; form.render(); + $('.layui-card-body').change(function(){ + console.log(window._filelist_cover_pic) + }) + //提交 var submitLock = false; form.on('submit(layui-form-submit)', function (obj) { @@ -192,6 +194,14 @@ $this->params['breadcrumbs'][] = $this->title; var url = 'urlManager->createUrl(["/admin/store/store-user-edit", 'id' => $model->id ? $model->id : 0]) ?>'; var returnUrl = ""; var data = obj.field; + var urls = [] + urls = window._filelist_cover_pic.map(function(val){ + console.log(val) + return val.url + }) + + data.cover_pic = JSON.stringify(urls); + // data.pic_urls = JSON.stringify(_gallery_pic_urls); // data.content = UE.getEditor('editor').getContent(); data._csrf = _csrf; diff --git a/modules/api/controllers/StoreController.php b/modules/api/controllers/StoreController.php index 532749b..ba1dbfa 100644 --- a/modules/api/controllers/StoreController.php +++ b/modules/api/controllers/StoreController.php @@ -49,6 +49,7 @@ class StoreController extends Controller 'api/store/shopowner', 'api/store/store-service', 'api/store/box', + 'api/store/box-list', 'api/store/shopowner-make', 'api/store/shopowner-make-list', 'api/store/check-out', @@ -234,7 +235,7 @@ class StoreController extends Controller /** - * 包厢 + * 案例列表 */ public function actionBox() { @@ -244,15 +245,29 @@ class StoreController extends Controller $form->page = $get['page'] ?? 1; $form->limit = $get['limit'] ?? 99; - $form->box_id = $get['box_id']; - $form->store_id = $get['store_id']; - $form->date = $get['date']; - $form->user_id = \Yii::$app->user->identity->id; + $form->keywords = $get['keywords'] ?? 99; $data = $form->search(); return $this->responseHandler($data); } + /** + * 案例列表 + */ + public function actionBoxList() + { + $request = Yii::$app->request; + $get = $request->get(); + $form = new BoxForm(); + + $form->page = $get['page'] ?? 1; + $form->limit = $get['limit'] ?? 99; + + $data = $form->lists(); + return $this->responseHandler($data); + } + + /** * showdoc * @catalog 门店申请 diff --git a/modules/api/controllers/UserController.php b/modules/api/controllers/UserController.php index a04cca0..6d512c9 100644 --- a/modules/api/controllers/UserController.php +++ b/modules/api/controllers/UserController.php @@ -22,6 +22,7 @@ use app\models\UserInformation; use app\modules\api\behaviors\LoginBehavior; use app\modules\api\models\CommentForm; use app\modules\api\models\UserBasicInfoForm; +use app\modules\api\models\UserCollectForm; use app\modules\api\models\UserModifyForm; class UserController extends Controller @@ -32,7 +33,11 @@ class UserController extends Controller 'login' => [ 'class' => LoginBehavior::className(), 'ignore' => [ - 'api/user/add-qrcode-find' + 'api/user/add-qrcode-find', +// 'api/user/user-collect-list', + 'api/user/user-collect-hot', +// 'api/user/user-collect', +// 'api/user/user-collect-del', ] ] ]); @@ -67,7 +72,7 @@ class UserController extends Controller $form = new UserBasicInfoForm(); $form->cx_mch_id = $this->cx_mch_id; $form->user_id = \Yii::$app->user->isGuest ? 0 : \Yii::$app->user->identity->id; - $form->pid = \Yii::$app->request->get('pid',0); + $form->pid = \Yii::$app->request->get('pid', 0); $data = $form->search(); return $this->responseHandler($data); } @@ -343,7 +348,7 @@ class UserController extends Controller return $this->responseHandler($data); } $user_id = \Yii::$app->user->identity->id; - $order = Order::find()->where(['is_delete' => 0, 'status' => [1,2], 'user_id' => $user_id])->orderBy(['id' => SORT_DESC])->one(); + $order = Order::find()->where(['is_delete' => 0, 'status' => [1, 2], 'user_id' => $user_id])->orderBy(['id' => SORT_DESC])->one(); if (empty($order) || empty($order->store_id)) { return $this->responseHandler(['code' => 1, 'msg' => '没有正在进行中的订单,无法呼叫']); } @@ -388,19 +393,19 @@ class UserController extends Controller return $this->responseHandler($data); } $user_id = 0; - if(!empty(\Yii::$app->user->identity)){ - $user_id = \Yii::$app->user->identity->id ? \Yii::$app->user->identity->id :0; + if (!empty(\Yii::$app->user->identity)) { + $user_id = \Yii::$app->user->identity->id ? \Yii::$app->user->identity->id : 0; } $store_id = \Yii::$app->request->post('store_id'); $ball_id = \Yii::$app->request->post('ball_id'); - if(!empty($ball_id)){ + if (!empty($ball_id)) { $unionid = $ball_id; $type = 2; - }else{ + } else { $unionid = $store_id; $type = 1; } - $value = ['user_id' => $user_id,'store_id'=>$store_id,'ball_id'=>$ball_id]; + $value = ['user_id' => $user_id, 'store_id' => $store_id, 'ball_id' => $ball_id]; $value = json_encode($value); $obj = new QrcodeRecord(); $obj->unionid = $unionid; @@ -423,9 +428,9 @@ class UserController extends Controller $redis_name = "api:cxaibc:qrcode:date:list"; \Yii::$app->redis->lpush($redis_name,$date);*/ return $this->responseHandler([ - 'code'=>0, - 'msg'=>'ok', - 'data'=>'' + 'code' => 0, + 'msg' => 'ok', + 'data' => '' ]); } @@ -555,20 +560,21 @@ class UserController extends Controller * @description 获取分销列表 * @method get * @url /api/user/user-next-list - * @return {"code":0,"msg":"ok","data":{}} * @param page int 页码 * @param limit int 页数 * @return_param nickname string 昵称 * @return_param avatar_url string 头像 * @return_param mobile_phone string 手机号 + * @return {"code":0,"msg":"ok","data":{}} */ - public function actionUserNextList(){ + public function actionUserNextList() + { $form = new UserBasicInfoForm(); $form->cx_mch_id = $this->cx_mch_id; $form->user_id = \Yii::$app->user->identity->id; - $page = \Yii::$app->request->get('page',1); - $limit = \Yii::$app->request->get('limit',10); - $data = $form->actionUserNextList($page,$limit); + $page = \Yii::$app->request->get('page', 1); + $limit = \Yii::$app->request->get('limit', 10); + $data = $form->actionUserNextList($page, $limit); return $this->responseHandler($data); } @@ -597,4 +603,79 @@ class UserController extends Controller } + /** + * showdoc + * @catalog 用户收藏列表 + * @title 用户收藏列表 + * @description 用户收藏列表 + * @method get + * @url /api/user/user-collect-list + * @return {"code":0,"msg":"ok","data":{}} + */ + public function actionUserCollectList() + { + $form = new UserCollectForm(); + $form->user_id = \Yii::$app->user->identity->id; +// $form->user_id = 124; + $data = $form->search(); + return $this->responseHandler($data); + } + + + /** + * showdoc + * @catalog 用户收藏列表 + * @title 用户收藏列表 + * @description 用户收藏列表 + * @method get + * @url /api/user/user-collect-list + * @return {"code":0,"msg":"ok","data":{}} + */ + public function actionUserCollectHot() + { + $form = new UserCollectForm(); + $data = $form->hot(); + return $this->responseHandler($data); + } + + /** + * showdoc + * @catalog 用户收藏 + * @title 用户收藏 + * @description 用户收藏 + * @method get + * @url /api/user/user-collect + * @return {"code":0,"msg":"ok","data":{}} + */ + public function actionUserCollect() + { + $form = new UserCollectForm(); + $form->user_id = \Yii::$app->user->identity->id; + $goods_id = \Yii::$app->request->post('goods_id'); + +// $form->user_id = 124; + $form->goods_id = $goods_id; + + $data = $form->collect(); + return $this->responseHandler($data); + } + + + /** + * 取消收藏 + * @return array + * @throws \Throwable + * @throws \yii\db\StaleObjectException + */ + public function actionUserCollectDel() + { + $form = new UserCollectForm(); + $id = \Yii::$app->request->post('id'); + +// $form->user_id = 124; + $form->user_id = \Yii::$app->user->identity->id; + $form->id = $id; + $data = $form->del(); + return $this->responseHandler($data); + } } \ No newline at end of file diff --git a/modules/api/models/BoxForm.php b/modules/api/models/BoxForm.php index a1eda31..b0eee23 100644 --- a/modules/api/models/BoxForm.php +++ b/modules/api/models/BoxForm.php @@ -23,6 +23,7 @@ use app\models\GoodsHub; use app\models\Order; use app\models\OrderDetail; use app\models\Store; +use app\models\StoreBj; use app\models\User; use app\components\auth\AToken; use app\components\EncryptHelper; @@ -39,12 +40,8 @@ class BoxForm extends ApiModel public $page; //页数 public $pageCount; // 总页数 - public $store_id; - public $box_id; - public $interval = 1; - - public $date; - public $user_id; + public $bj_id; + public $keywords; public function rules() @@ -59,151 +56,55 @@ class BoxForm extends ApiModel public function search() { - if (empty($this->box_id)) { - return $this->apiReturnError('包厢ID不能为空'); - } + $query = Box::find()->alias('b') + ->leftJoin(['goods' => Goods::tableName()], 'b.goods_id=goods.id') + ->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id') + ->leftJoin(['storeBj' => StoreBj::tableName()], 'b.bj_id=storeBj.id') + ->select('b.id,b.created_at,b.cover_pic,b.status,goodHub.name as goods_name,storeBj.name as bj_name') + ->where([ + 'b.status' => 1, + 'b.is_delete' => 0 + ]) + ->andFilterWhere(['b.bj_id' => $this->bj_id]) + ->andFilterWhere(['OR', + ['like', 'goodHub.name', $this->keywords]]); - if (empty($this->date)) { - return $this->apiReturnError('预定日期不能为空'); - } - $where = ['id' => $this->box_id, 'status' => 1, 'is_delete' => 0]; + $count = $query->count(); + $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); + $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['b.created_at' => SORT_DESC])->asArray()->all(); + foreach ($list as $index => $item) { +// $item['business'] = $item['begin_time'] . '-' . $item['end_time']; + $list[$index]['created_at_cn'] = date("Y-m-d H:i", $item['created_at']); + if ($item['cover_pic'] != null) { + $pic_arr = json_decode($item['cover_pic'], true); - $list = Box::find()->where($where) - ->select('id,name,notice,money,pic_urls,content,device')->asArray()->one(); - - $list['device'] = json_decode($list['device'], true); - - if ($list['pic_urls']) { - $store_pics = json_decode($list['pic_urls'], true); - foreach ($store_pics as $k => $v) { - $list['pic_arr'][] = SiteHelper::getFullUrl($v); - } - unset($list['pic_urls']); - } - $s = strtotime($this->date); # 开始时间 - $arr = []; - for ($i = 0; $i < 24; $i++) { - $arr[$s] = [ - 'start' => date('H:i', $s), - 'stop' => date('H:i', $s + 60 * 60), - 'scope' => date('H:i', $s) . "-" . date('H:i', $s + 60 * 60), - 'status' => 0, - ]; - $s += 60 * 60; - } - $arr[$s - 60 * 60]['stop'] = date('H:59', $s - 60 * 60); - - // 获取已下单数据 - $query = Order::find()->alias('o') - ->innerJoin(['rt' => OrderDetail::tableName()], 'o.id=rt.order_id') - ->where(['o.store_id' => $this->store_id, 'coach_id' => $this->box_id, 'o.is_delete' => 0, 'o.cancel_status' => 0, 'o.plugin_sign' => 'box_book']) - ->andWhere(['IN', 'o.status', [0, 1]]) - ->select('rt.start_at as start,rt.end_at as stop,o.user_id,o.is_pay') - ->asArray() - ->all(); - if (!empty($query)) { - $t_arr = []; - foreach ($query as $key => $val) { - $t = strtotime(date('Y-m-d H:00', $val['start'])); - while (true) { - if ($t >= $val['stop']) { - break; + if (is_array($pic_arr)) { + foreach ($pic_arr as $key => $value) { + $arr[] = SiteHelper::getFullUrl($value); +// $pic_arr[] = $arr; } - // 如果是自己,可以继续选择,并且未支付 - if ($val['user_id'] == $this->user_id && empty($val['is_pay'])) { - $t_arr[$t] = 0; - } else { - $t_arr[$t] = 1; - } - $t += 60 * 60; - } - } - foreach ($arr as $key => $val) { - if (!empty($t_arr[$key])) { - $arr[$key]['status'] = 1; - $arr[$key]['data'] = $t_arr; + $list[$index]['cover_pic_arr'] = $arr; } } + } - return [ - 'code' => 0, - 'msg' => 'ok', - 'data' => $list, - 'date_list' => array_merge($arr), - 'data_res' => $query, - ]; + $data = []; + $data['code'] = 0; + $data['msg'] = 'ok'; + $data['data'] = $list; + $data['count'] = $count; + return $data; } - public function getBoxBookStatus($start_time, $end_time, $data) + public function lists() { - $start_time = strtotime($start_time); - $end_time = strtotime($end_time); - - $query = Order::find()->alias('o') - ->innerJoin(['rt' => OrderDetail::tableName()], 'o.id=rt.order_id') - ->where(['o.store_id' => $this->store_id, 'coach_id' => $this->box_id, 'o.is_delete' => 0, 'o.cancel_status' => 0]) - ->andWhere(['>=', 'rt.start_at', $start_time]) - ->andWhere(['<=', 'rt.end_at', $end_time]) - ->andWhere(['IN', 'o.status', [1, 3]]) - ->select('rt.start_at,rt.end_at') - ->asArray() -// $count_query = clone $query; - ->all(); -// -// var_dump($query->createCommand()->getRawSql()); -// die(); - - - if (!isset($query)) { - return false; - } - - //$beginTime1 订单预约的开始时间 $endTime1 订单预约的结束时间 - //$beginTime2 下单的开始时间 $endTime2 下单的结束时间 - - foreach ($query as $key => $value) { - $beginTime1 = $value['start_at']; - $endTime1 = $value['end_at']; - $beginTime2 = $data['start']; - $endTime2 = $data['stop']; - $date_diff = $this->is_time_cross($beginTime1, $endTime1, $beginTime2, $endTime2); - if ($date_diff == true) { - return true; - } - } - return false; + $store = StoreBj::find()->where(['is_delete' => 0, 'status' => 1])->asArray()->all(); + $data = []; + $data['code'] = 0; + $data['msg'] = 'ok'; + $data['data'] = $store; + return $data; } - - function is_time_cross($beginTime1 = '', $endTime1 = '', $beginTime2 = '', $endTime2 = '') - { - $status = $beginTime2 - $beginTime1; - if ($status > 0) { - $status2 = $beginTime2 - $endTime1; - if ($status2 > 0) { - return false; - } elseif ($status2 < 0) { - return true; - } else { - return false; - } - } elseif ($status < 0) { - $status2 = $endTime2 - $beginTime1; - if ($status2 > 0) { - return true; - } else if ($status2 < 0) { - return false; - } else { - return false; - } - } else { - $status2 = $endTime2 - $beginTime1; - if ($status2 == 0) { - return false; - } else { - return true; - } - } - } } \ No newline at end of file diff --git a/modules/api/models/UserCollectForm.php b/modules/api/models/UserCollectForm.php new file mode 100644 index 0000000..d395c6c --- /dev/null +++ b/modules/api/models/UserCollectForm.php @@ -0,0 +1,169 @@ + 1], + ]; + } + + + /** + * 收藏列表 + */ + public function search() + { + + if (empty($this->limit)) { + $this->limit = 10; + } + if (empty($this->page)) { + $this->page = 1; + } + $query = UserCollect::find()->alias('user') + ->leftJoin(['goods' => Goods::tableName()], 'user.goods_id=goods.id') + ->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id') + ->select('user.id,goods.id as goods_id,goodHub.cover_pic') + ->where([ + 'user.user_id' => $this->user_id, + ]); + + $count = $query->count(); + $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); + $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['user.id' => SORT_DESC])->asArray()->all(); + + foreach ($list as $key => $value) { + $value['cover_pic'] = SiteHelper::getFullUrl($value['cover_pic']); + $list[$key] = $value; + } + + $data = []; + $data['code'] = 0; + $data['msg'] = 'ok'; + $data['data'] = $list; + $data['count'] = $count; + return $data; + } + + + public function collect() + { + if (empty($this->goods_id)) { + return $this->apiReturnError('收藏的冠军错误'); + } + + $goods = Goods::findOne(['id' => $this->goods_id]); + if ($goods == null) { + return $this->apiReturnError('冠军不存在'); + + } + + $model = new UserCollect(); + $model->user_id = $this->user_id; + $model->goods_id = $this->goods_id; + if (!$model->save()) { + return $this->getModelError($model); + } + return [ + 'code' => 0, + 'msg' => '收藏成功' + ]; + + } + + + /** + * @return array + * @throws \Throwable + * @throws \yii\db\StaleObjectException + */ + public function del() + { + if (empty($this->id)) { + return $this->apiReturnError('收藏的ID错误'); + } + + $model = UserCollect::findOne(['id' => $this->id]); + if ($model == null) { + return $this->apiReturnError('收藏不存在'); + + } + + if (!$model->delete()) { + return $this->getModelError($model); + } + return [ + 'code' => 0, + 'msg' => '取消收藏成功' + ]; + } + + + public function hot() + { + $query = Goods::find()->alias('goods') + ->leftJoin(['goodHub' => GoodsHub::tableName()], 'goods.goods_hub_id=goodHub.id') + ->select('goods.id as goods_id,goodHub.cover_pic') + ->where([ + 'goods.is_delete' => 0, + ]); + + $count = $query->count(); + $pagination = new Pagination(['totalCount' => $count, 'pageSize' => 20]); + $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['goods.id' => SORT_DESC])->asArray()->all(); + foreach ($list as $key => $value) { + $value['cover_pic'] = SiteHelper::getFullUrl($value['cover_pic']); + $list[$key] = $value; + } + $data = []; + $data['code'] = 0; + $data['msg'] = 'ok'; + $data['data'] = $list; + $data['count'] = $count; + return $data; + + } +} \ No newline at end of file