MdFoodController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\modules\client\controllers\v1;
  8. use app\models\Banner;
  9. use app\models\Cart;
  10. use app\models\District;
  11. use app\models\FoodCart;
  12. use app\models\FoodFlag;
  13. use app\models\FoodTableNumber;
  14. use app\models\Goods;
  15. use app\models\GoodsPic;
  16. use app\models\Md;
  17. use app\models\MdFoodsQrcode;
  18. use app\models\Option;
  19. use app\models\Store;
  20. use app\models\FoodExtGoods;
  21. use app\models\User;
  22. use app\modules\client\controllers\BaseController;
  23. use app\modules\client\models\v1\FoodAddCartForm;
  24. use app\modules\client\models\v1\FoodCartListForm;
  25. use app\plugins\food\models\client\IndexForm;
  26. use app\plugins\food\models\FoodCat;
  27. use app\plugins\food\models\FoodGoods;
  28. use app\utils\Tools;
  29. use yii\base\BaseObject;
  30. use yii\helpers\Json;
  31. use app\modules\admin\models\MchForm;
  32. class MdFoodController extends BaseController
  33. {
  34. /**
  35. * 商品列表
  36. */
  37. public function actionGoodsList() {
  38. $store_id = get_store_id();
  39. $md_id = get_params('md_id');
  40. $lat = get_params('lat', 0);
  41. $lng = get_params('lng', 0);
  42. $type = get_params('type', null);
  43. $mch_id = intval(get_mch_id());
  44. if ($md_id > 0) {
  45. $md = Md::findOne($md_id);
  46. $name = $md->name;
  47. $distance = Tools::getDistance($lat, $lng, $md->latitude, $md->longitude);
  48. $food_page_title = Option::get('food_page_title', $md_id, 'md', '')['value'] ?: '手机点餐';
  49. } else {
  50. $store = Store::findOne(get_store_id());
  51. $name = $store->name;
  52. $store_lat = '';
  53. $store_long = '';
  54. $coordinate = explode(',', $store->coordinate);
  55. if ($coordinate) {
  56. $store_lat = $coordinate[0];
  57. $store_long = $coordinate[1];
  58. }
  59. $distance = Tools::getDistance($lat, $lng, $store_lat, $store_long);
  60. $food_page_title = Option::get('food_page_title', $store->id, 'store', '')['value'] ?: '手机点餐';
  61. }
  62. if($mch_id){
  63. $mchInfo = (new MchForm(['store_id' => get_store_id(), 'mch_id' => $mch_id, 'lat' => $lat, 'lng' => $lng]))->mchInfo();
  64. $name = $mchInfo['data']->name;
  65. $distance = $mchInfo['dis'];
  66. $food_page_title = Option::get('food_page_title', $mch_id, 'mch', '')['value'] ?: '手机点餐';
  67. }
  68. if (isset($md)) {
  69. $md_id_ = $md_id;
  70. // if (!$md->is_single) {
  71. // $md_id_ = [0, -1, $md_id];
  72. // }
  73. } else {
  74. $md_id_ = [0, -1];
  75. }
  76. // 分类
  77. $cats = FoodCat::find()->where([
  78. 'store_id' => $store_id, 'is_delete' => 0, 'is_show' => 1, 'mch_id' => intval($mch_id), 'md_id' => $md_id_
  79. ])->orderBy('sort desc')
  80. ->select('id, name as title, desc as subtitle, pic_url as icon')
  81. ->asArray()->all();
  82. // if (empty($cats)) {
  83. // return $this->asJson([
  84. // 'code' => 1,
  85. // 'msg' => '分类未找到'
  86. // ]);
  87. // }
  88. foreach ($cats as $key => &$cat) {
  89. $where = [
  90. 'store_id' => $store_id,
  91. 'cat_id' => $cat['id'],
  92. 'is_delete' => 0,
  93. 'status' => 1
  94. ];
  95. $where['mch_id'] = $mch_id;
  96. $where['md_food_id'] = $md_id_;
  97. $query = Goods::find()->where($where);
  98. if ($type) {
  99. $query->andWhere(['like', 'delivery_type', $type]);
  100. }
  101. $goods_list = $query->select('id, store_id, food_ext_goods_id, mch_id, md_food_id, name, cover_pic as goods_pic, key_word as desc, price, original_price, attr, use_attr, virtual_sales as sales')->orderBy('sort desc')->asArray()->all();
  102. if (empty($goods_list)) {
  103. // 如果当前分类下无商品,不作展示
  104. unset($cats[$key]);
  105. continue;
  106. }
  107. foreach ($goods_list as $k => $goods) {
  108. $goods_list[$k]['attr'] = Json::decode($goods['attr']);
  109. $goods_info = Goods::findOne($goods['id']);
  110. $goods_list[$k]['attr_group_list'] = $goods_info->getAttrGroupList();
  111. $goods_list[$k]['num'] = $goods_info->getNum();
  112. $feg = [];
  113. $goods_list[$k]['food_ext_goods'] = FoodExtGoods::getAttr($goods['food_ext_goods_id'], $goods['store_id'], $goods['md_food_id'], $feg, $mch_id);
  114. $goods_list[$k]['food_ext_goods_model'] = $feg;
  115. }
  116. $cat['list'] = $goods_list;
  117. }
  118. sort($cats);
  119. // 轮播图
  120. $banner_arr = [];
  121. $banners = Banner::find()->where([
  122. 'store_id' => $store_id,
  123. 'type' => Banner::TYPE_FOOD,
  124. 'is_delete' => 0,
  125. 'mch_id' => intval($mch_id),
  126. 'md_id' => $md_id_
  127. ])->orderBy('sort desc')
  128. ->asArray()->all();
  129. if (!empty($banners)) {
  130. foreach ($banners as $value) {
  131. $banner_arr[] = [
  132. 'image' => $value['pic_url'],
  133. 'link' => $value['page_url'],
  134. 'title' => $value['title']
  135. ];
  136. }
  137. }
  138. return $this->asJson([
  139. 'code' => 0,
  140. 'msg' => 'success',
  141. 'data' => [
  142. 'goods_list' => $cats,
  143. 'md_name' => $name,
  144. '$mchInfo' => $mchInfo,
  145. 'md' => $md,
  146. 'distance' => $distance,
  147. 'banner' => $banner_arr,
  148. 'food_page_title' => $food_page_title
  149. ]
  150. ]);
  151. }
  152. /**
  153. * 店铺信息
  154. */
  155. public function actionMdInfo() {
  156. $md_id = get_params('md_id');
  157. $mch_id = intval(get_mch_id());
  158. if ($md_id > 0) {
  159. $md = Md::findOne($md_id);
  160. $md_info['name'] = $md->name;
  161. $md_info['mobile'] = $md->mobile;
  162. $md_info['address'] = $md->address;
  163. $md_info['province_name'] = District::findOne($md->province)->name;
  164. $md_info['city_name'] = District::findOne($md->city)->name;
  165. $md_info['district_name'] = District::findOne($md->district)->name;
  166. $md_info['cover_url'] = $md->cover_url;
  167. $md_info['open_status'] = $md->open_status;
  168. $md_info['shop_time_type'] = $md->shop_time_type;
  169. $md_info['latitude'] = $md->latitude;
  170. $md_info['longitude'] = $md->longitude;
  171. $md_info['start_time'] = $md->start_time;
  172. $md_info['end_time'] = $md->end_time;
  173. $md_info['food_page_title'] = Option::get('food_page_title', $md_id, 'md', '')['value'];
  174. } else if($mch_id){
  175. $mchInfo = (new MchForm(['store_id' => get_store_id(), 'mch_id' => $mch_id]))->mchInfo()['data'];
  176. $md_info['name'] = $mchInfo->name;
  177. $md_info['mobile'] = $mchInfo->tel;
  178. $md_info['address'] = $mchInfo->address;
  179. $md_info['province_name'] = District::findOne($mchInfo->province_id)->name;
  180. $md_info['city_name'] = District::findOne($mchInfo->city_id)->name;
  181. $md_info['district_name'] = District::findOne($mchInfo->district_id)->name;
  182. $md_info['cover_url'] = $mchInfo->logo;
  183. $md_info['open_status'] = $mchInfo->is_open;
  184. $md_info['shop_time_type'] = 0;
  185. $md_info['latitude'] = $mchInfo->latitude;
  186. $md_info['longitude'] = $mchInfo->longitude;
  187. $md_info['start_time'] = '';
  188. $md_info['end_time'] = '';
  189. $md_info['food_open_time'] = Option::get('food_open_time', $mch_id, 'mch', '')['value'];
  190. $md_info['food_page_title'] = Option::get('food_page_title', $mch_id, 'mch', '')['value'];
  191. } else {
  192. $store = Store::findOne(get_store_id());
  193. $md_info['name'] = $store->name;
  194. $md_info['mobile'] = $store->contact_tel;
  195. $md_info['address'] = $store->address;
  196. $md_info['province_name'] = District::findOne($store->province_id)->name;
  197. $md_info['city_name'] = District::findOne($store->city_id)->name;
  198. $md_info['district_name'] = District::findOne($store->district_id)->name;
  199. $md_info['cover_url'] = $store->logo;
  200. $md_info['open_status'] = $store->open_status;
  201. $md_info['shop_time_type'] = $store->shop_time_type;
  202. $md_info['latitude'] = '';
  203. $md_info['longitude'] = '';
  204. $coordinate = explode(',', $store->coordinate);
  205. if ($coordinate) {
  206. $md_info['latitude'] = $coordinate[0];
  207. $md_info['longitude'] = $coordinate[1];
  208. }
  209. $md_info['start_time'] = $store->s_time;
  210. $md_info['end_time'] = $store->e_time;
  211. $md_info['food_page_title'] = Option::get('food_page_title', $store->id, 'store', '')['value'];
  212. }
  213. return $this->asJson([
  214. 'code' => 0,
  215. 'msg' => 'success',
  216. 'data' => $md_info
  217. ]);
  218. }
  219. /**
  220. * 店铺信息
  221. */
  222. public function actionGetMdInfo() {
  223. $md_id = get_md_id();
  224. if ($md_id > 0) {
  225. $md = Md::findOne($md_id);
  226. $md_info['name'] = $md->name;
  227. $md_info['mobile'] = $md->mobile;
  228. $md_info['address'] = $md->address;
  229. $md_info['province_name'] = District::findOne($md->province)->name;
  230. $md_info['city_name'] = District::findOne($md->city)->name;
  231. $md_info['district_name'] = District::findOne($md->district)->name;
  232. $md_info['cover_url'] = $md->cover_url;
  233. $md_info['open_status'] = $md->open_status;
  234. $md_info['shop_time_type'] = $md->shop_time_type;
  235. $md_info['latitude'] = $md->latitude;
  236. $md_info['longitude'] = $md->longitude;
  237. $md_info['start_time'] = $md->start_time;
  238. $md_info['end_time'] = $md->end_time;
  239. } else {
  240. $store = Store::findOne(get_store_id());
  241. $md_info['name'] = $store->name;
  242. $md_info['mobile'] = $store->contact_tel;
  243. $md_info['address'] = $store->address;
  244. $md_info['province_name'] = District::findOne($store->province_id)->name;
  245. $md_info['city_name'] = District::findOne($store->city_id)->name;
  246. $md_info['district_name'] = District::findOne($store->district_id)->name;
  247. $md_info['cover_url'] = $store->logo;
  248. $md_info['open_status'] = $store->open_status;
  249. $md_info['shop_time_type'] = $store->shop_time_type;
  250. $md_info['latitude'] = '';
  251. $md_info['longitude'] = '';
  252. $coordinate = explode(',', $store->coordinate);
  253. if ($coordinate) {
  254. $md_info['latitude'] = $coordinate[0];
  255. $md_info['longitude'] = $coordinate[1];
  256. }
  257. $md_info['start_time'] = $store->s_time;
  258. $md_info['end_time'] = $store->e_time;
  259. }
  260. return $this->asJson([
  261. 'code' => 0,
  262. 'msg' => 'success',
  263. 'data' => $md_info
  264. ]);
  265. }
  266. public function actionGoodsDetail() {
  267. $goods = Goods::findOne(['store_id' => get_store_id(), 'is_delete' => 0, 'status' => 1, 'id' => get_params('id')]);
  268. if (!$goods) {
  269. return $this->asJson([
  270. 'code' => 1,
  271. 'msg' => '商品不存在'
  272. ]);
  273. }
  274. $feg = [];
  275. $goods_info = [
  276. 'goods_pic' => array_column(GoodsPic::find()->where(['goods_id' => $goods->id, 'is_delete' => 0])->select('pic_url')->asArray()->all(), 'pic_url'),
  277. 'detail' => $goods->detail,
  278. 'name' => $goods->name,
  279. 'desc' => $goods->key_word,
  280. 'price' => $goods->price,
  281. 'original_price' => $goods->original_price,
  282. 'id' => $goods->id,
  283. 'sales' => $goods->virtual_sales,
  284. 'attr_group_list' => $goods->getAttrGroupList(),
  285. 'attr' => $goods->attr,
  286. 'food_ext_goods' => FoodExtGoods::getAttr($goods['food_ext_goods_id'], $goods['store_id'], $goods['md_food_id'], $feg),
  287. 'food_ext_goods_model' => $feg,
  288. 'use_attr' => $goods->use_attr,
  289. 'num' => $goods->getNum(),
  290. ];
  291. return $this->asJson([
  292. 'code' => 0,
  293. 'msg' => 'success',
  294. 'data' => $goods_info
  295. ]);
  296. }
  297. //初始化商城购物车
  298. public function actionInitGoodsCart() {
  299. try {
  300. $table_num = get_params('table_num');
  301. $md_id = (int)get_params('md_id');
  302. $flag_id = 0;
  303. if ($table_num) {
  304. $food_flag = FoodFlag::findOne(['store_id' => get_store_id(), 'mch_id' => intval(get_mch_id()), 'md_id' => $md_id, 'table_num' => $table_num, 'status' => 0, 'type' => 1]);
  305. if (!$food_flag) {
  306. $food_flag = new FoodFlag();
  307. $food_flag->md_id = $md_id;
  308. $food_flag->store_id = get_store_id();
  309. get_mch_id() && $food_flag->mch_id = intval(get_mch_id());
  310. $food_flag->table_num = $table_num;
  311. $food_flag->type = 1;
  312. $food_flag->user_id = get_user_id();
  313. $food_flag->is_parent = 1;
  314. $food_flag->save();
  315. } else {
  316. if ($food_flag->created_at < (time() - 60 * 60 * 2)) {
  317. FoodFlag::updateAll(['status' => 1], [
  318. 'store_id' => get_store_id(),
  319. 'mch_id' => intval(get_mch_id()),
  320. 'md_id' => $md_id > 0 ? $md_id : [0, -1],
  321. 'table_num' => $table_num,
  322. 'status' => 0,
  323. 'type' => 1
  324. ]);
  325. $food_flag = new FoodFlag();
  326. $food_flag->md_id = $md_id;
  327. $food_flag->store_id = get_store_id();
  328. get_mch_id() && $food_flag->mch_id = intval(get_mch_id());
  329. $food_flag->table_num = $table_num;
  330. $food_flag->type = 1;
  331. $food_flag->user_id = get_user_id();
  332. $food_flag->is_parent = 1;
  333. $food_flag->save();
  334. }
  335. }
  336. $flag_id = $food_flag->id;
  337. }
  338. $userInfo = User::findOne(['id' => $food_flag->user_id]);
  339. return $this->asJson([
  340. 'code' => 0,
  341. 'msg' => '获取成功',
  342. 'data' => [
  343. 'flag_id' => $flag_id,
  344. 'avatar_url' => $userInfo->avatar_url,
  345. 'nickname' => $userInfo->nickname,
  346. 'is_parent' => $food_flag->user_id == get_user_id() ? 1 : 0,
  347. ]
  348. ]);
  349. } catch (\Exception $e) {
  350. return $this->asJson([
  351. 'code' => 0,
  352. 'msg' => $e->getMessage(),
  353. 'data' => [
  354. 'flag_id' => 0
  355. ]
  356. ]);
  357. }
  358. }
  359. /**
  360. * 添加购物车
  361. */
  362. public function actionAddCart() {
  363. $mch_id = intval(get_mch_id());
  364. $post = post_params();
  365. $md_id = get_md_id() ?: -1;
  366. $form = new FoodAddCartForm();
  367. $form->store_id = get_store_id();
  368. $form->user_id = get_user_id();
  369. $form->md_id = $md_id;
  370. if (isset($post['flag_id']) && !empty($post['flag_id'])) {
  371. $form->flag_id = $post['flag_id'];
  372. } else if (isset($post['table_num']) && !empty($post['table_num'])) {
  373. $food_flag = FoodFlag::findOne(['store_id' => get_store_id(), 'mch_id' => intval($mch_id), 'md_id' => $md_id, 'table_num' => $post['table_num'], 'status' => 0, 'type' => 1]);
  374. if ($food_flag) {
  375. $form->flag_id = $food_flag->id;
  376. } else {
  377. $food_flag = new FoodFlag();
  378. $food_flag->md_id = $md_id;
  379. $food_flag->store_id = get_store_id();
  380. $food_flag->table_num = $post['table_num'];
  381. $food_flag->type = 1;
  382. $food_flag->user_id = get_user_id();
  383. $food_flag->is_parent = 1;
  384. $food_flag->save();
  385. $form->flag_id = $food_flag->id;
  386. }
  387. } else {
  388. $food_flag = new FoodFlag();
  389. $food_flag->md_id = $md_id;
  390. $food_flag->store_id = get_store_id();
  391. $food_flag->table_num = 0;
  392. $food_flag->type = 0;
  393. $food_flag->user_id = get_user_id();
  394. $food_flag->is_parent = 1;
  395. $food_flag->save();
  396. $form->flag_id = $food_flag->id;
  397. }
  398. if (isset($post['attr_list']) && !empty($post['attr_list'])) {
  399. $attr_list = Json::decode($post['attr_list']);
  400. $form->goods_id = $post['goods_id'];
  401. $error = 0;
  402. foreach ($attr_list as $value){
  403. $form->attr = Json::encode($value['attr_list']);
  404. $form->num = $value['number'];
  405. $status = $form->save();
  406. if($status['code'] != 0){
  407. $error++;
  408. }
  409. }
  410. if ($error > 0) {
  411. return $this->asJson([
  412. 'code' => 0,
  413. 'data' => [
  414. 'flag_id' => $form->flag_id
  415. ],
  416. 'msg' => '添加成功,' . $error . "个失败",
  417. ]);
  418. } else {
  419. return $this->asJson([
  420. 'code' => 0,
  421. 'data' => [
  422. 'flag_id' => $form->flag_id
  423. ],
  424. 'msg' => '添加成功'
  425. ]);
  426. }
  427. } else {
  428. $form->attributes = post_params();
  429. return $this->asJson($form->save());
  430. }
  431. }
  432. public function actionQueryGoods() {$arr = [];
  433. if(get_mch_id()){
  434. $arr['mch'] = 1;
  435. $arr['mch_id'] = intval(get_mch_id());
  436. }
  437. $flag_id = get_params('flag_id');
  438. $form = new FoodCartListForm();
  439. $form->store_id = get_store_id();
  440. $form->table_num = get_params('table_num', 0);
  441. $form->flag_id = $flag_id;
  442. return $this->asJson($form->search($arr));
  443. }
  444. /**
  445. * 购物车详情
  446. */
  447. public function actionUpdateNum()
  448. {
  449. $cart = FoodCart::findOne(['id' => post_params('cart_id', 0), 'is_delete' => 0]);
  450. if (empty($cart)) {
  451. return $this->asJson([
  452. 'code' => 1,
  453. 'msg' => '参数错误'
  454. ]);
  455. }
  456. $cart->num = (int)post_params('num');
  457. if ($cart->save()) {
  458. if ($cart->num == 0) {
  459. $cart->is_delete = 1;
  460. $cart->save();
  461. }
  462. return $this->asJson([
  463. 'code' => 0,
  464. 'msg' => '保存成功'
  465. ]);
  466. } else {
  467. return $this->asJson([
  468. 'code' => 1,
  469. 'msg' => '保存失败'
  470. ]);
  471. }
  472. }
  473. public function actionClearCart() {
  474. $flag_id = post_params('flag_id');
  475. $table_num = get_params('table_num');
  476. if (empty($flag_id)) {
  477. $food_flag = FoodFlag::findOne(['store_id' => get_store_id(), 'table_num' => $table_num, 'md_id' => get_md_id(), 'status' => 0]);
  478. $flag_id = $food_flag->id;
  479. } else {
  480. $food_flag = FoodFlag::findOne(['store_id' => get_store_id(), 'id' => $flag_id, 'status' => 0]);
  481. }
  482. if (empty($flag_id)) {
  483. return $this->asJson([
  484. 'code' => 1,
  485. 'msg' => '参数异常'
  486. ]);
  487. }
  488. if (!$food_flag) {
  489. return $this->asJson([
  490. 'code' => 1,
  491. 'msg' => '数据异常'
  492. ]);
  493. }
  494. $user_id = post_params('user_id', 0);
  495. $params = [
  496. 'flag_id' => $flag_id,
  497. 'is_delete' => 0
  498. ];
  499. if (!empty($user_id)) {
  500. $params['user_id'] = $user_id;
  501. }
  502. FoodCart::updateAll(['is_delete' => 1], $params);
  503. return $this->asJson([
  504. 'code' => 0,
  505. 'msg' => '清空成功'
  506. ]);
  507. }
  508. public function actionClose() {
  509. $flag_id = post_params('flag_id');
  510. $user_id = get_user_id();
  511. $food_flag = FoodFlag::findOne(['id' => $flag_id, 'status' => 0, 'md_id' => get_md_id(), 'store_id' => get_store_id()]);
  512. if ($food_flag->user_id != $user_id) {
  513. return $this->asJson([
  514. 'code' => 1,
  515. 'msg' => '只有发起人才能清空购物车'
  516. ]);
  517. }
  518. if (empty($flag_id)) {
  519. return $this->asJson([
  520. 'code' => 1,
  521. 'msg' => '参数异常'
  522. ]);
  523. }
  524. FoodCart::updateAll(['is_delete' => 1], ['flag_id' => $flag_id]);
  525. FoodFlag::updateAll(['status' => 1], ['id' => $flag_id]);
  526. return $this->asJson([
  527. 'code' => 0,
  528. 'msg' => '关单成功'
  529. ]);
  530. }
  531. public function actionUserComplete() {
  532. $flag_id = post_params('flag_id');
  533. $user_id = get_user_id();
  534. $food_flag = FoodFlag::findOne(['id' => $flag_id, 'status' => 0, 'md_id' => get_md_id(), 'store_id' => get_store_id()]);
  535. if (!$food_flag) {
  536. return $this->asJson([
  537. 'code' => 1,
  538. 'msg' => '数据异常'
  539. ]);
  540. }
  541. if (empty($flag_id)) {
  542. return $this->asJson([
  543. 'code' => 1,
  544. 'msg' => '参数异常'
  545. ]);
  546. }
  547. FoodCart::updateAll(['status' => 1], ['flag_id' => $flag_id, 'user_id' => $user_id, 'is_delete' => 0]);
  548. return $this->asJson([
  549. 'code' => 0,
  550. 'msg' => '成功'
  551. ]);
  552. }
  553. public function actionCompleteStatus() {
  554. $flag_id = get_params('flag_id');
  555. $user_id = get_user_id();
  556. $food_cart = FoodCart::findOne(['flag_id' => $flag_id, 'user_id' => $user_id, 'is_delete' => 0]);
  557. return $this->asJson([
  558. 'code' => 0,
  559. 'msg' => 'success',
  560. 'data' => [
  561. 'status' => $food_cart->status
  562. ]
  563. ]);
  564. }
  565. public function actionFlag() {
  566. $mch_id = intval(get_mch_id());
  567. $food_flag = new FoodFlag();
  568. $food_flag->md_id = get_md_id() ?: -1;
  569. $mch_id && $food_flag->mch_id = $mch_id;
  570. $food_flag->store_id = get_store_id();
  571. $food_flag->table_num = 0;
  572. $food_flag->type = 0;
  573. $food_flag->status = 0;
  574. $food_flag->user_id = get_user_id();
  575. $food_flag->is_parent = 1;
  576. $food_flag->save();
  577. return $this->asJson([
  578. 'code' => 0,
  579. 'msg' => 'success',
  580. 'data' => [
  581. 'flag_id' => $food_flag->id
  582. ]
  583. ]);
  584. }
  585. public function actionStatus() {
  586. $flag_id = get_params('flag_id');
  587. $store_id = get_store_id();
  588. $md_id = get_md_id() ?: [0,-1];
  589. $food_flag = FoodFlag::findOne(['id' => $flag_id, 'store_id' => $store_id, 'md_id' => $md_id]);
  590. if (!$food_flag) {
  591. return $this->asJson([
  592. 'code' => 1,
  593. 'msg' => '未找到数据'
  594. ]);
  595. }
  596. return $this->asJson([
  597. 'code' => 0,
  598. 'msg' => 'success',
  599. 'data' => [
  600. 'table_num' => $food_flag->table_num,
  601. 'type' => $food_flag->type,
  602. 'order_id' => $food_flag->order_id,
  603. 'user_id' => $food_flag->user_id,
  604. 'status' => $food_flag->status
  605. ]
  606. ]);
  607. }
  608. //通过平台点餐二维码获取门店以及桌号信息
  609. public function actionGetQrcodeInfo() {
  610. $qrcode_id = post_params('qrcode_id');
  611. $qrcode = MdFoodsQrcode::findOne(['id' => $qrcode_id, 'is_delete' => 0, 'store_id' => get_store_id()]);
  612. $data = [
  613. 'md_id' => -1,
  614. 'food_table_num' => null,
  615. 'status' => 0
  616. ];
  617. if ($qrcode) {
  618. $data['status'] = 1;
  619. if ($qrcode->table_num || $qrcode->md_id) {
  620. $data['md_id'] = $qrcode->md_id ?: -1;
  621. if ($qrcode->table_num) {
  622. $table_num = FoodTableNumber::find()->where(['id' => $qrcode->table_num])->select('num')->asArray()->one();
  623. if ($table_num) {
  624. $data['food_table_num'] = $table_num['num'];
  625. }
  626. }
  627. }
  628. }
  629. return $this->asJson([
  630. 'code' => 0,
  631. 'msg' => '获取成功',
  632. 'data' => $data
  633. ]);
  634. }
  635. }