FurnitureController.php 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178
  1. <?php
  2. namespace App\Http\Controllers\Api\V1;
  3. use App\Models\AlbumBannerModel;
  4. use App\Models\AlbumCommentsModel;
  5. use App\Models\AlbumManufacturerModel;
  6. use App\Models\AlbumNavModel;
  7. use App\Models\AlbumNewsModel;
  8. use App\Models\AlbumOrderModel;
  9. use App\Models\AlbumPartsModel;
  10. use App\Models\AlbumProductAttrModel;
  11. use App\Models\AlbumProgressModel;
  12. use App\Models\AlbumReviewModel;
  13. use App\Models\AlbumUserModel;
  14. use App\Models\FurnitureFormidModel;
  15. use App\Models\FurnitureGoodsModel;
  16. use App\Models\UserInfoModel;
  17. use Carbon\Carbon;
  18. use Illuminate\Http\Request;
  19. use Illuminate\Support\Facades\DB;
  20. use MGQrCodeReader\MGQrCodeReader;
  21. use Validator, Auth ,Image;
  22. use App\Services\Base\ErrorCode;
  23. use EasyWeChat\Factory;
  24. use Zxing\Qrcode\QRCodeReader;
  25. use ZBarCodeImage,ZBarCodeScanner;
  26. class FurnitureController extends Controller
  27. {
  28. protected $app;
  29. private $wechat_app;
  30. /**
  31. * @api {post} /api/furniture/setting 首页基本设置
  32. * @apiDescription 首页基本设置
  33. * @apiGroup Furniture
  34. * @apiPermission none
  35. * @apiVersion 0.1.0
  36. * @apiParam {string} store_id 店铺ID
  37. * @apiSuccessExample {json} Success-Response:
  38. * HTTP/1.1 200 OK
  39. * {
  40. * "status": true,
  41. * "status_code": 0,
  42. * "message": "",
  43. * "data": {
  44. * "setting": {
  45. * "name": "某某厂家",
  46. * "goods_app_id": "afdasfa", //商品要跳转的appid
  47. * "goods_app_path": "page/goods/goods", //商品要跳转的url
  48. * "illustrated_name": "在线画册",
  49. * "avatar": "http://s1.xcx.com/upload/s1test/20180716/bb123f13bf8a42f0a86b55e7bf861400.png",
  50. * "notice": "这是一条公告测试!",
  51. * "advertising_pic": ""
  52. * },
  53. * "banner": [ //轮播图
  54. * ...
  55. * {
  56. * "id": 4,
  57. * "store_id": 1,
  58. * "pic_url": "https://u3.9026.com/upload/temp_pic/20171013/da1d53cd93bfa4c8ed34939314ca18fb.jpg",
  59. * "title": "轮播图测试",
  60. * "page_url": "news/news",
  61. * "sort": 87,
  62. * }
  63. * ...
  64. * ],
  65. * "navbar": [ //底部导航栏
  66. * ...
  67. * {
  68. * "id": 9,
  69. * "store_id": 1,
  70. * "name": "联系我们",
  71. * "url": "/pages/index/index",
  72. * "open_type": "1",
  73. * "pic_url": "http://s1.xcx.com/upload/agent_show/20180702/7e638f0ca464f8096fba8a658b49d556.png",
  74. * "sort": 100,
  75. * "created_at": "2018-07-16 16:05:29",
  76. * "updated_at": "2018-07-20 18:08:37",
  77. * "deleted_at": null,
  78. * "mobile": "13407570861",
  79. * "address": null,
  80. * "app_id": null,
  81. * "state": 0,
  82. * "lon": null,
  83. * "lat": null
  84. * }
  85. * ...
  86. * ],
  87. * "menus": [ //顶部导航栏
  88. * ...
  89. * {
  90. * "id": 9,
  91. * "store_id": 1,
  92. * "name": "联系我们",
  93. * "url": "/pages/index/index",
  94. * "open_type": "1",
  95. * "pic_url": "http://s1.xcx.com/upload/agent_show/20180702/7e638f0ca464f8096fba8a658b49d556.png",
  96. * "sort": 100,
  97. * "created_at": "2018-07-16 16:05:29",
  98. * "updated_at": "2018-07-20 18:08:37",
  99. * "deleted_at": null,
  100. * "mobile": "13407570861",
  101. * "address": null,
  102. * "app_id": null,
  103. * "state": 1,
  104. * "lon": null,
  105. * "lat": null
  106. * }
  107. * ...
  108. * ]
  109. *
  110. * }
  111. * }
  112. * @apiErrorExample {json} Error-Response:
  113. * HTTP/1.1 400 Bad Request
  114. * {
  115. * "state": false,
  116. * "code": 1000,
  117. * "message": "传入参数不正确",
  118. * "data": null or []
  119. * }
  120. * 可能出现的错误代码:
  121. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  122. */
  123. public function furnitureSetting(Request $request)
  124. {
  125. $validator = Validator::make($request->all(), [
  126. 'store_id' => 'required',
  127. ], [
  128. 'store_id.required' => '店铺信息未知',
  129. ]);
  130. if ($validator->fails()) {
  131. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  132. }
  133. $store_id = $request->store_id;
  134. //小程序設置
  135. $setting = AlbumManufacturerModel::where('store_id', $store_id)->first(['name', 'goods_app_id', 'goods_app_path', 'illustrated_name', 'avatar', 'notice', 'advertising_pic']);
  136. //轮播图
  137. $banner = AlbumBannerModel::where('store_id', $store_id)->orderByDesc('sort')->get();
  138. //底部导航栏
  139. $navbar = AlbumNavModel::where([['store_id', $store_id], ['state', 0]])->orderByDesc('sort')->get();
  140. //顶部菜单栏
  141. $menus = AlbumNavModel::where([['store_id', $store_id], ['state', 1]])->orderByDesc('sort')->get();
  142. return $this->api(compact('setting', 'banner', 'navbar', 'menus'));
  143. }
  144. /**
  145. * @api {get} /api/furniture/news_detail 获取新闻详情
  146. * @apiDescription 获取新闻详情(news_detail)
  147. * @apiGroup Furniture
  148. * @apiPermission none
  149. * @apiVersion 0.1.0
  150. * @apiParam {int} store_id 商户id
  151. * @apiParam {int} newsid 新闻id
  152. * @apiSuccessExample {json} Success-Response:
  153. * HTTP/1.1 200 OK
  154. * {
  155. * "status": true,
  156. * "status_code": 0,
  157. * "message": "",
  158. * "data": {
  159. * news": {
  160. * "id": 5,
  161. * "store_id": 2,
  162. * "title": "测试时",
  163. * "thumb": null,
  164. * "content": "<p>啊师傅阿凡达</p>",
  165. * "bad": 0, //淘汰
  166. * "commonly": 0, //一般
  167. * "like": 0, //喜欢
  168. * "viewed": 0, //浏览次数
  169. * "sort": 87,
  170. * "created_at": "2018-05-28 09:33:01",
  171. * "updated_at": "2018-05-28 09:33:01",
  172. * "avatar": "https://u3.9026.com/upload/common/20171013/137d21eb6dbaca67475c8ca27640dcfc.png"
  173. * },
  174. * "news_comments": {
  175. * "current_page": 1,
  176. * "data": [
  177. * {
  178. * "id": 13,
  179. * "store_id": 2,
  180. * "user_id": 6,
  181. * "comments_id": 0, //被评论id 0:表示对新闻评论
  182. * "content": "adff",
  183. * "created_at": "2018-06-14 15:49:38",
  184. * "updated_at": "2018-06-14 15:49:38",
  185. * "news_id": 5, //新闻id
  186. * "deleted_at": null,
  187. * "sys_reply": "",
  188. * "username": "Wesley",
  189. * "avatar": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLnEDDuGRN9Dl7icBbph1JRvmQ7x2D4tiaGGVHApGAu9FCy9yb1bOcboIctAjRsyic4Ucn3z7K3QCUyg/132",
  190. * "replys": {
  191. * "current_page": 1,
  192. * "data": [],
  193. * "first_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  194. * "from": null,
  195. * "last_page": 1,
  196. * "last_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  197. * "next_page_url": null,
  198. * "path": "http://localhost:8082/api/furniture/news_detail",
  199. * "per_page": 5,
  200. * "prev_page_url": null,
  201. * "to": null,
  202. * "total": 0
  203. * }
  204. * }
  205. * ],
  206. * "first_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  207. * "from": 1,
  208. * "last_page": 1,
  209. * "last_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  210. * "next_page_url": null,
  211. * "path": "http://localhost:8082/api/furniture/news_detail",
  212. * "per_page": 5,
  213. * "prev_page_url": null,
  214. * "to": 1,
  215. * "total": 1
  216. *
  217. * }
  218. * }
  219. * @apiErrorExample {json} Error-Response:
  220. * HTTP/1.1 400 Bad Request
  221. * {
  222. * "state": false,
  223. * "code": 1000,
  224. * "message": "传入参数不正确",
  225. * "data": null or []
  226. * }
  227. * 可能出现的错误代码:
  228. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  229. */
  230. public function furnitureNewsDetail(Request $request)
  231. {
  232. $news_id = request('newsid');
  233. $news = AlbumNewsModel::find($news_id);
  234. $news->viewed += 1;
  235. $news->save();
  236. $news->avatar = AlbumManufacturerModel::where('store_id', $request->get('store_id'))->first()->avatar;
  237. $news_comments = AlbumCommentsModel::where('news_id', $news_id)
  238. ->where('comments_id', 0)
  239. ->orderByDesc('created_at')
  240. ->paginate(5);
  241. foreach ($news_comments as $item) {
  242. $user = AlbumUserModel::find($item->user_id);
  243. $item->username = $user->username;
  244. $item->avatar = $user->avatar;
  245. $item->replys = AlbumCommentsModel::find($item->id)->replys()->paginate(5);
  246. foreach ($item->replys as $i) {
  247. $iuser = AlbumUserModel::find($i->user_id);
  248. $i->username = $iuser->username;
  249. $i->avatar = $iuser->avatar;
  250. }
  251. }
  252. return $this->api(compact('news', 'news_comments'));
  253. }
  254. /**
  255. * @api {get} /api/furniture/news_list 获取新闻列表
  256. * @apiDescription 获取新闻列表(news_list)
  257. * @apiGroup Furniture
  258. * @apiPermission none
  259. * @apiVersion 0.1.0
  260. * @apiParam {int} store_id 商户id 模拟值为1
  261. * @apiSuccessExample {json} Success-Response:
  262. * HTTP/1.1 200 OK
  263. * {
  264. * "status": true,
  265. * "status_code": 0,
  266. * "message": "",
  267. * "data": {
  268. * "current_page": 1, //当前页
  269. * "data": [
  270. * ...
  271. * {
  272. * "id": 1,
  273. * "store_id": 1,
  274. * "title": "123123",
  275. * "thumb": "http://s1.xcx.com/upload/agent_pic/20180702/19b0e148f1c9f2b6c3667c81bb06a687.jpg",
  276. * "content": "<p>1232123123123</p>",
  277. * "bad": 0,
  278. * "commonly": 0,
  279. * "like": 0,
  280. * "viewed": 133,
  281. * "sort": 127,
  282. * "created_at": "2018-05-24 15:21:42",
  283. * "updated_at": "2018-07-20 16:58:48"
  284. * },
  285. *...
  286. * ],
  287. * "first_page_url": "http://s1.xcx.com/api/furniture/news_list?page=1", //首页url
  288. * "from": 1,
  289. * "last_page": 1,
  290. * "last_page_url": "http://s1.xcx.com/api/furniture/news_list?page=1", //尾页url
  291. * "next_page_url": null, //下一页url
  292. * "path": "http://s1.xcx.com/api/furniture/news_list",
  293. * "per_page": 5,
  294. * "prev_page_url": null, //上一页url
  295. * "to": 3,
  296. * "total": 3
  297. *
  298. * }
  299. * }
  300. * @apiErrorExample {json} Error-Response:
  301. * HTTP/1.1 400 Bad Request
  302. * {
  303. * "state": false,
  304. * "code": 1000,
  305. * "message": "传入参数不正确",
  306. * "data": null or []
  307. * }
  308. * 可能出现的错误代码:
  309. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  310. */
  311. public function furnitureNewsList(Request $request)
  312. {
  313. $validator = Validator::make($request->all(), [
  314. 'store_id' => 'required',
  315. ], [
  316. 'store_id.required' => '店铺信息未知',
  317. ]);
  318. if ($validator->fails()) {
  319. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  320. }
  321. $store_id = $request->store_id;
  322. $news = AlbumNewsModel::where('store_id', $store_id)->orderByDesc('sort')->paginate(5);
  323. return $this->api($news);
  324. }
  325. /**
  326. * @api {get} /api/furniture/add_comments 添加新闻评论
  327. * @apiDescription 添加新闻评论(news_list)
  328. * @apiGroup Furniture
  329. * @apiPermission Passport
  330. * @apiVersion 0.1.0
  331. * @apiParam {int} store_id 商户ID
  332. * @apiParam {int} news_id 新闻ID
  333. * @apiParam {int} content 评论内容
  334. * @apiParam {int} comments_id 被回复的评论ID。对新闻评论:0; 对评论回复:被回复的评论的具体ID
  335. * @apiSuccessExample {json} Success-Response:
  336. * HTTP/1.1 200 OK
  337. * {
  338. * "status": true,
  339. * "status_code": 0,
  340. * "message": "",
  341. * "data": {
  342. * "res": []//结果
  343. *
  344. * }
  345. * }
  346. * @apiErrorExample {json} Error-Response:
  347. * HTTP/1.1 400 Bad Request
  348. * {
  349. * "state": false,
  350. * "code": 1000,
  351. * "message": "传入参数不正确",
  352. * "data": null or []
  353. * }
  354. * 可能出现的错误代码:
  355. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  356. * 401 token已过期,请重新登录
  357. */
  358. public function furnitureAddComments(Request $request)
  359. {
  360. $user = Auth('api')->user();
  361. if (!$user) {
  362. $data = [
  363. 'code' => 401,
  364. 'msg' => 'token已过期,请重新登录'
  365. ];
  366. return $this->api($data);
  367. }
  368. $data = $request->all();
  369. if ($data['content']) {
  370. $data['user_id'] = $user->id;
  371. $res = AlbumCommentsModel::create($data);
  372. $res = ['state' => true, "code" => "200", "message" => "评论成功", "data" => $res];
  373. } else {
  374. $res = ['state' => false, "code" => "1000", "message" => "传入参数不正确", "data" => null];
  375. }
  376. return $this->api(compact('res'));
  377. }
  378. /**
  379. * @api {get} /api/furniture/addtolike 新闻点赞
  380. * @apiDescription 新闻点赞
  381. * @apiGroup Furniture
  382. * @apiPermission None
  383. * @apiVersion 0.1.0
  384. * @apiParam {int} store_id 商户ID
  385. * @apiParam {int} news_id 新闻ID
  386. * @apiParam {int} [like] 喜欢 (参数:1)
  387. * @apiSuccessExample {json} Success-Response:
  388. * HTTP/1.1 200 OK
  389. * {
  390. * "status": true,
  391. * "status_code": 0,
  392. * "message": "",
  393. * "data": {
  394. * "res": []//结果
  395. *
  396. * }
  397. * }
  398. * @apiErrorExample {json} Error-Response:
  399. * HTTP/1.1 400 Bad Request
  400. * {
  401. * "state": false,
  402. * "code": 1000,
  403. * "message": "传入参数不正确",
  404. * "data": null or []
  405. * }
  406. * 可能出现的错误代码:
  407. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  408. */
  409. public function addToLike(Request $request)
  410. {
  411. $validator = Validator::make($request->all(), [
  412. 'store_id' => 'required',
  413. 'newsid' => 'required',
  414. ], [
  415. 'store_id.required' => '店铺信息未知',
  416. 'newsid.required' => '评论id未知',
  417. ]);
  418. if ($validator->fails()) {
  419. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  420. }
  421. $news_id = request('newsid');
  422. $news = AlbumNewsModel::find($news_id);
  423. if (request('like') == 1) {
  424. $news->like += 1;
  425. }
  426. $news->save();
  427. $data = [
  428. 'state' => 'true',
  429. 'code' => 200,
  430. 'msg' => '请求成功'
  431. ];
  432. return $this->api($data);
  433. }
  434. /**
  435. * @api {get} /api/furniture/getmorecomments 获取全部评论/回复
  436. * @apiDescription 获取全部评论/回复(getmorecomments)
  437. * @apiGroup Furniture
  438. * @apiPermission none
  439. * @apiVersion 0.1.0
  440. * @apiParam {int} store_id 商户id
  441. * @apiParam {int} id 评论/回复 id
  442. * @apiSuccessExample {json} Success-Response:
  443. * HTTP/1.1 200 OK
  444. * {
  445. * "status": true,
  446. * "status_code": 0,
  447. * "message": "",
  448. * "data": {
  449. * comments": {
  450. * "id": 13,
  451. * "store_id": 2,
  452. * "user_id": 6,
  453. * "comments_id": 0, //被评论id 0:表示对新闻评论
  454. * "content": "adff",
  455. * "created_at": "2018-06-14 15:49:38",
  456. * "updated_at": "2018-06-14 15:49:38",
  457. * "news_id": 5, //新闻id
  458. * "deleted_at": null,
  459. * "sys_reply": "",
  460. * "username": "Wesley",
  461. * "avatar": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLnEDDuGRN9Dl7icBbph1JRvmQ7x2D4tiaGGVHApGAu9FCy9yb1bOcboIctAjRsyic4Ucn3z7K3QCUyg/132",
  462. * },
  463. * "comments_replys": {
  464. * "current_page": 1,
  465. * "data": [
  466. * {
  467. * "id": 13,
  468. * "store_id": 2,
  469. * "user_id": 6,
  470. * "comments_id": 13, //被评论id 0:表示对新闻评论
  471. * "content": "adff",
  472. * "created_at": "2018-06-14 15:49:38",
  473. * "updated_at": "2018-06-14 15:49:38",
  474. * "news_id": 5, //新闻id
  475. * "deleted_at": null,
  476. * "sys_reply": "",
  477. * "username": "Wesley",
  478. * "avatar": "https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTLnEDDuGRN9Dl7icBbph1JRvmQ7x2D4tiaGGVHApGAu9FCy9yb1bOcboIctAjRsyic4Ucn3z7K3QCUyg/132",
  479. * "replys": {
  480. * "current_page": 1,
  481. * "data": [],
  482. * "first_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  483. * "from": null,
  484. * "last_page": 1,
  485. * "last_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  486. * "next_page_url": null,
  487. * "path": "http://localhost:8082/api/furniture/news_detail",
  488. * "per_page": 5,
  489. * "prev_page_url": null,
  490. * "to": null,
  491. * "total": 0
  492. * }
  493. * }
  494. * ],
  495. * "first_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  496. * "from": 1,
  497. * "last_page": 1,
  498. * "last_page_url": "http://localhost:8082/api/furniture/news_detail?page=1",
  499. * "next_page_url": null,
  500. * "path": "http://localhost:8082/api/furniture/news_detail",
  501. * "per_page": 5,
  502. * "prev_page_url": null,
  503. * "to": 1,
  504. * "total": 1
  505. *
  506. * }
  507. * }
  508. */
  509. public function getMoreComments(Request $request)
  510. {
  511. $validator = Validator::make($request->all(), [
  512. 'store_id' => 'required',
  513. 'id' => 'required',
  514. ], [
  515. 'store_id.required' => '店铺信息未知',
  516. 'id.required' => '评论id未知',
  517. ]);
  518. if ($validator->fails()) {
  519. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  520. }
  521. $store_id = $request->store_id;
  522. $comments = AlbumCommentsModel::find(request('id'));
  523. $user = AlbumUserModel::find($comments->user_id);
  524. $comments->avatar = $user->avatar;;
  525. $comments->username = $user->username;
  526. $comments_replys = AlbumCommentsModel::where('comments_id', $comments->id)
  527. ->orderByDesc('created_at')
  528. ->paginate(5);
  529. foreach ($comments_replys as $item) {
  530. $user = AlbumUserModel::find($item->user_id);
  531. $item->username = $user->username;
  532. $item->avatar = $user->avatar;
  533. $item->replys = AlbumCommentsModel::find($item->id)->replys()->paginate(5);
  534. foreach ($item->replys as $i) {
  535. $iuser = AlbumUserModel::find($i->user_id);
  536. $i->username = $iuser->username;
  537. $i->avatar = $iuser->avatar;
  538. }
  539. }
  540. return $this->api(compact('comments', 'comments_replys'));
  541. }
  542. /**
  543. * @api {get} /api/furniture/goods_list 获取产品列表
  544. * @apiDescription 获取产品列表(goods_list)
  545. * @apiGroup Furniture
  546. * @apiPermission none
  547. * @apiVersion 0.1.0
  548. * @apiParam {int} store_id 商户id 模拟值为1
  549. * @apiSuccessExample {json} Success-Response:
  550. * HTTP/1.1 200 OK
  551. * {
  552. * "status": true,
  553. * "status_code": 0,
  554. * "message": "",
  555. * "data": {
  556. * "current_page": 1,
  557. * "data": [
  558. * ...
  559. * {
  560. * "id": 1,
  561. * "goods_id":12 //要跳转的小程序id
  562. * "name": "床垫测试",
  563. * "img": "http://s1.xcx.com/upload/img/20180720/70f926022b933658d269106172e18bf0.png",
  564. * "sort": 99,
  565. * "status": 1,
  566. * "store_id": 1,
  567. * "created_at": "2018-07-20 14:56:42",
  568. * "updated_at": "2018-07-20 17:36:23",
  569. * "price": 199
  570. * }
  571. * ...
  572. * ],
  573. * "first_page_url": "http://s1.xcx.com/api/furniture/goods_list?page=1",
  574. * "from": 1,
  575. * "last_page": 1,
  576. * "last_page_url": "http://s1.xcx.com/api/furniture/goods_list?page=1",
  577. * "next_page_url": null,
  578. * "path": "http://s1.xcx.com/api/furniture/goods_list",
  579. * "per_page": 5,
  580. * "prev_page_url": null,
  581. * "to": 4,
  582. * "total": 4
  583. * }
  584. * }
  585. * @apiErrorExample {json} Error-Response:
  586. * HTTP/1.1 400 Bad Request
  587. * {
  588. * "state": false,
  589. * "code": 1000,
  590. * "message": "传入参数不正确",
  591. * "data": null or []
  592. * }
  593. * 可能出现的错误代码:
  594. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  595. */
  596. public function furnitureGoodsList(Request $request)
  597. {
  598. $validator = Validator::make($request->all(), [
  599. 'store_id' => 'required',
  600. ], [
  601. 'store_id.required' => '店铺信息未知',
  602. ]);
  603. if ($validator->fails()) {
  604. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  605. }
  606. $store_id = $request->store_id;
  607. $goods = FurnitureGoodsModel::where('store_id', $store_id)
  608. ->where('status', 1)
  609. ->orderByDesc('sort')
  610. ->paginate(5);
  611. return $this->api($goods);
  612. }
  613. /**
  614. * @api {post} /api/furniture/service_login 登陆(login)
  615. * @apiDescription 登陆(login)
  616. * @apiGroup Furniture_Service
  617. * @apiPermission none
  618. * @apiVersion 0.1.0
  619. * @apiParam {string} code 小程序登录生成的code
  620. * @apiParam {string} nickName 微信昵称
  621. * @apiParam {string} avatar 微信头像
  622. * @apiSuccessExample {json} Success-Response:
  623. * HTTP/1.1 200 OK
  624. * {
  625. * "status": true,
  626. * "status_code": 0,
  627. * "message": "",
  628. * "data": {
  629. * "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjUzMzYwMzNlNzIwOTE3YjE0NDc4YjgxMWY5MmI4MjBmMThlNDgxNjJjZGFkYmEwNGI3ZjliZTNmZjRlMTY2YjU4NGU4MzJhN2RmYzY2ZTcxIn0.eyJhdWQiOiIxIiwianRpIjoiNTMzNjAzM2U3MjA5MTdiMTQ0NzhiODExZjkyYjgyMGYxOGU0ODE2MmNkYWRiYTA0YjdmOWJlM2ZmNGUxNjZiNTg0ZTgzMmE3ZGZjNjZlNzEiLCJpYXQiOjE1MzI0MjA3NDAsIm5iZiI6MTUzMjQyMDc0MCwiZXhwIjoxNTYzOTU2NzQwLCJzdWIiOiIyIiwic2NvcGVzIjpbXX0.YnuRiJI9jlt-KeQ480UEpLWCUU8FEJvlTRtAdjOlP0BWmcdo0E9rGS4hriYnpfJOn09Cw0aRYuc4dgQYL_JWD2fodlGg1LRIvPTOtvM5TiwM86kQJawvfFw7X7p9nOhxrFa5Tyir0cdTcV0SmQbq8KIptjdR8j7wUTByKhONexBXtNnlZSpw70ckTQrAstkn97IDwPo04hhGhf6eDPc8ler0HONiAVqbRvvNG6yHShJarP1hxyXrYN2BM0N7dtLD_8Sr8XaXL6ie4rRFVM4fNwpn74DkiDwXY6-5Xet6mzPvvzARAmU5vJ7JHhcL1N7m7poNp6YCx_mZAZ1z8PGDKrtQWoVeAmIxo7qtI6jvgvUpEFnJQ-KHCunXflNBL-vIYW4o3llnYqku1pcBdAUfkYLjYUgB3EZio280_8q-6Q24VAMiHZ58AjYvHHJJssdOa3dVHGD9Iq2z1dWR6gmZ4MgGCunCcAe9L_CbDm7VtMq3nKj4a1WScRiMD5nlKAHgy4O32rtNXqDr5T-eV-QNa4ZOv4VZ1AR-WE4RkO4ArKPaFxgSa9mak98PU8NHcPaJ_B3eDbvtwtMloTXWSQP08cmUPXKjEwXvszdkUt-ZWirw5Sd22h3qMdCI3gcvzT4_rnDKCEk37P09fUIK8LZrS4s2xOhueHziMzheAF0QekI",
  630. * "user": {
  631. * "id": 2,
  632. * "store_id": 1,
  633. * "username": "roger",
  634. * "role": 0, //用户类型:0:普通用户;1:生产部 2:包装部 3:经理
  635. * "wechat_open_id": "olAS94uwfTdsL3nDnvG67p_v5Vks",
  636. * "avatar": "https://wx.qlogo.cn/mmopen/vi_32/IOcxico8l4A7W3qxDeA53Id5kVAj2ibUGvQib9QibicTp5c1RNshDj6EKz2PKWp3reHfib0xxT4wa7jJzcb7a4EggkVw/132",
  637. * "is_dealer": 0 //是否经销商 0:不是 1:是
  638. * },
  639. * "session_key": 'pGgENkTGXLQD4hPuTF8yEw=='
  640. * }
  641. * }
  642. * @apiErrorExample {json} Error-Response:
  643. * HTTP/1.1 400 Bad Request
  644. * {
  645. * "state": false,
  646. * "code": 1000,
  647. * "message": "传入参数不正确",
  648. * "data": null or []
  649. * }
  650. * 可能出现的错误代码:
  651. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  652. * 40029 获取openid失败
  653. */
  654. public function serviceLogin(Request $request)
  655. {
  656. $validator = Validator::make($request->all(),
  657. [
  658. 'code' => 'required',
  659. 'store_id' => 'required'
  660. ],
  661. [
  662. 'code.required' => 'code不能为空!',
  663. 'store_id.required' => 'store_id不能为空!'
  664. ]
  665. );
  666. if ($validator->fails()) {
  667. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  668. }
  669. $storeid = $request->get('store_id');
  670. $this->wechat_app = AlbumManufacturerModel::where('store_id', $storeid)->first();
  671. $config = [
  672. 'app_id' => $this->wechat_app->service_app_id,
  673. 'secret' => $this->wechat_app->service_app_secret,
  674. // 下面为可选项
  675. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  676. 'response_type' => 'array',
  677. ];
  678. $app = Factory::miniProgram($config);
  679. $code = $request->get('code');
  680. $session = $app->auth->session($code);
  681. if (!isset($session['openid'])) {
  682. $data = [
  683. 'code' => 40029,
  684. 'msg' => '获取openID失败'
  685. ];
  686. return $this->api($data);
  687. }
  688. \Log::info(json_encode($session));
  689. $openid = $session['openid'];
  690. $session_key = $session['session_key'];
  691. $userinfo = AlbumUserModel::where('wechat_open_id', $openid)->where('store_id', $storeid)->first(['id', 'username', 'wechat_open_id', 'avatar']);
  692. if (!$userinfo) {
  693. $data['wechat_open_id'] = $openid;
  694. $data['username'] = $request->get('nickName');
  695. $data['avatar'] = $request->get('avatar');
  696. $data['store_id'] = $request->get('store_id');
  697. $data['is_dealer'] = 0;
  698. $userinfo = AlbumUserModel::create($data);
  699. }
  700. if (Auth::loginUsingId($userinfo->id)) {
  701. $user = Auth::user();
  702. $token = $user->createToken($user->id . '-' . $user->openid)->accessToken;
  703. return $this->api(compact('token', 'user', 'session_key'));
  704. } else {
  705. return $this->error(ErrorCode::INCORRECT_USER_OR_PASS);
  706. }
  707. }
  708. /**
  709. * @api {get} /api/furniture/getfurnitureads 获取首页广告
  710. * @apiDescription 获取首页广告
  711. * @apiGroup Furniture_Service
  712. * @apiPermission none
  713. * @apiVersion 0.1.0
  714. * @apiParam {string} store_id
  715. * @apiSuccessExample {json} Success-Response:
  716. * HTTP/1.1 200 OK
  717. * {
  718. * "status": true,
  719. * "status_code": 0,
  720. * "message": "",
  721. * "data": {
  722. * "furniture_ads_pic": "http://s1.xcx.com/upload/img/20180720/70f926022b933658d269106172e18bf0.png"
  723. * }
  724. * }
  725. * @apiErrorExample {json} Error-Response:
  726. * HTTP/1.1 400 Bad Request
  727. * {
  728. * "state": false,
  729. * "code": 1000,
  730. * "message": "传入参数不正确",
  731. * "data": null or []
  732. * }
  733. * 可能出现的错误代码:
  734. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  735. */
  736. public function getFurnitureAds(Request $request)
  737. {
  738. $validator = Validator::make($request->all(),
  739. [
  740. 'store_id' => 'required'
  741. ],
  742. [
  743. 'store_id.required' => 'store_id不能为空!'
  744. ]
  745. );
  746. if ($validator->fails()) {
  747. return $this->error(ErrorCode::CLIENT_WRONG_PARAMS, '传入参数不正确!', $validator->messages());
  748. }
  749. $ads = AlbumManufacturerModel::where('store_id', request('store_id'))->first(['furniture_ads_pic']);
  750. return $this->api($ads);
  751. }
  752. /**
  753. * @api {get} /api/furniture/getattr 获取产品属性
  754. * @apiDescription 获取产品属性
  755. * @apiGroup Furniture_Service
  756. * @apiPermission none
  757. * @apiVersion 0.1.0
  758. * @apiParam {string} store_id
  759. * @apiParam {string} [id] 默认获取品类,传品类id获取该品类的型号,传型号id获取该型号的颜色
  760. * @apiSuccessExample {json} Success-Response:
  761. * HTTP/1.1 200 OK
  762. * {
  763. * "status": true,
  764. * "status_code": 0,
  765. * "message": "",
  766. * "data": [
  767. * ...
  768. * {
  769. * "id": 1,
  770. * "name": "冰箱",
  771. * "pid": 0,
  772. * "attr_type": 0,
  773. * "sort": 100,
  774. * "store_id": 1,
  775. * "deleted_at": null,
  776. * "created_at": "2018-06-28 02:55:26",
  777. * "updated_at": "2018-06-28 02:59:29"
  778. * },
  779. * ...
  780. * ]
  781. * }
  782. * @apiErrorExample {json} Error-Response:
  783. * HTTP/1.1 400 Bad Request
  784. * {
  785. * "state": false,
  786. * "code": 1000,
  787. * "message": "传入参数不正确",
  788. * "data": null or []
  789. * }
  790. * 可能出现的错误代码:
  791. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  792. */
  793. public function getAttr(Request $request)
  794. {
  795. $store_id = request('store_id');
  796. $pid = request('id') ? request('id') : 0;
  797. $attr = AlbumProductAttrModel::where('store_id', $store_id)->where('pid', $pid)->orderBy('sort', 'desc')->get();
  798. return $this->api($attr);
  799. }
  800. /**
  801. * @api {post} /api/furniture/createorder 创建售后订单
  802. * @apiDescription 创建售后订单
  803. * @apiGroup Furniture_Service
  804. * @apiPermission Passport
  805. * @apiVersion 0.1.0
  806. * @apiParam {string} store_id Store_id
  807. * @apiParam {string} category 产品类别
  808. * @apiParam {string} type 产品型号
  809. * @apiParam {string} [color] 产品颜色
  810. * @apiParam {string} question 问题描述
  811. * @apiParam {string} [picture] 图片
  812. * @apiParam {string} customer_name 联系人姓名
  813. * @apiParam {string} customer_phone 联系人电话
  814. * @apiParam {string} customer_address 联系人地址
  815. * @apiSuccessExample {json} Success-Response:
  816. * HTTP/1.1 200 OK
  817. * {
  818. * "status": true,
  819. * "status_code": 0,
  820. * "message": "",
  821. * "data": {
  822. * "category": [
  823. *
  824. * ]
  825. * }
  826. * }
  827. * @apiErrorExample {json} Error-Response:
  828. * HTTP/1.1 400 Bad Request
  829. * {
  830. * "state": false,
  831. * "code": 1000,
  832. * "message": "传入参数不正确",
  833. * "data": null or []
  834. * }
  835. * 可能出现的错误代码:
  836. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  837. */
  838. public function createOrder(Request $request)
  839. {
  840. $user = Auth('api')->user();
  841. if (!$user) {
  842. $data = [
  843. 'code' => 401,
  844. 'msg' => 'token已过期,请重新登录'
  845. ];
  846. return $this->api($data);
  847. }
  848. $validator = Validator::make($request->all(), [
  849. 'store_id' => 'required',
  850. 'category' => 'required',
  851. 'type' => 'required',
  852. 'question' => 'required',
  853. 'customer_name' => 'required',
  854. 'customer_phone' => 'required|regex:/^1[345789][0-9]{9}$/',
  855. 'customer_address' => 'required',
  856. ], [
  857. 'store_id.required' => '站点信息未知',
  858. 'category.required' => '产品分类不能为空',
  859. 'type.required' => '产品型号不能为空',
  860. 'question.required' => '问题描述不能为空',
  861. 'customer_name.required' => '姓名不能为空',
  862. 'customer_phone.required' => '联系方式不能为空',
  863. 'customer_phone.regex' => '请输入正确的手机号码',
  864. 'customer_address.required' => '收货地址不能为空',
  865. ]);
  866. if ($validator->fails()) {
  867. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  868. }
  869. $data = $request->all();
  870. $data['status'] = 0;
  871. $data['sno'] = date('YmdHmis');
  872. $data['type'] = $data['category'] . $data['type'];
  873. if (isset($data['picture'])) {
  874. $data['picture'] = implode(',', $data['picture']);
  875. }
  876. $data['user_id'] = $user->id;
  877. $res = AlbumOrderModel::create($data);
  878. if ($res) {
  879. $this->getQrcode(request('store_id'), $res->id);
  880. }
  881. return $this->api(compact('res'));
  882. }
  883. /**
  884. * @api {get} /api/furniture/getorder 获取订单信息
  885. * @apiDescription 获取订单
  886. * @apiGroup Furniture_Service
  887. * @apiPermission none
  888. * @apiVersion 0.1.0
  889. * @apiParam {string} store_id
  890. * @apiParam {string} [user_id] (填写user_id,查询用户个人订单,不填则查询店铺订单)
  891. * @apiParam {string} [status](可填) (选填 0:待审核;1:待生产;2:生产中;3:待发货;4:运输中/未签收 5:已签收/待评价 6:已评价 7:已取消 null:全部订单 8:生产部全部订单/个人待发货订单 9:包装部全部订单)
  892. * @apiParam {string} [expected] (1:查询逾期的订单)
  893. * @apiSuccessExample {json} Success-Response:
  894. * HTTP/1.1 200 OK
  895. * {
  896. * "status": true,
  897. * "status_code": 0,
  898. * "message": "",
  899. * "data": {
  900. * "current_page": 1,
  901. * "data": [
  902. * ...
  903. * {
  904. * "id": 1,
  905. * "sno": "s1001",
  906. * "qrcode": "qr.png",
  907. * "status": 1,
  908. * "category": "冰箱",
  909. * "type": "s1002",
  910. * "color": "白色",
  911. * "picture": "1.ipg",
  912. * "question": "问题测试",
  913. * "customer_name": "wesley",
  914. * "customer_phone": "18380257014",
  915. * "customer_address": "成都市新都区",
  916. * "user_id": 1,
  917. * "producer_id": null,
  918. * "packer_id": null,
  919. * "price": 50,
  920. * "expected_time": "2018-07-05",
  921. * "remark": null,
  922. * "store_id": 1,
  923. * "created_at": "2018-07-03 17:18:26",
  924. * "updated_at": "2018-07-05 14:53:42"
  925. * }
  926. * ...
  927. * ],
  928. * "first_page_url": "http://s1.xcx.com/api/furniture/getorder?page=1",
  929. * "from": 1,
  930. * "last_page": 1,
  931. * "last_page_url": "http://s1.xcx.com/api/furniture/getorder?page=1",
  932. * "next_page_url": null,
  933. * "path": "http://s1.xcx.com/api/furniture/getorder",
  934. * "per_page": 5,
  935. * "prev_page_url": null,
  936. * "to": 2,
  937. * "total": 2 //订单数量
  938. * }
  939. * }
  940. * @apiErrorExample {json} Error-Response:
  941. * HTTP/1.1 400 Bad Request
  942. * {
  943. * "state": false,
  944. * "code": 1000,
  945. * "message": "传入参数不正确",
  946. * "data": null or []
  947. * }
  948. * 可能出现的错误代码:
  949. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  950. */
  951. public function getOrder(Request $request)
  952. {
  953. $validator = Validator::make($request->all(), [
  954. 'store_id' => 'required',
  955. ], [
  956. 'store_id.required' => '站点信息未知',
  957. ]);
  958. if ($validator->fails()) {
  959. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  960. }
  961. $storeid = request('store_id');
  962. $userid = request('user_id');
  963. if ($userid) {
  964. if (request('status') !== null) {
  965. if (request('status') == 8) {
  966. $order = AlbumOrderModel::where('store_id', $storeid)->where('user_id', $userid)->whereIn('status', [1, 2, 3])->orderBy('updated_at', 'desc')->paginate(5);
  967. } else {
  968. $order = AlbumOrderModel::where('store_id', $storeid)->where('user_id', $userid)->where('status', request('status'))->orderBy('updated_at', 'desc')->paginate(5);
  969. }
  970. }
  971. if (request('expected')) {
  972. $order = AlbumOrderModel::where('store_id', $storeid)
  973. ->where('user_id', $userid)
  974. ->where('status', '>', 0)
  975. ->where('status', '<', 5)
  976. ->where(DB::raw("DATEDIFF(NOW(),expected_time)"), '>', 0)
  977. ->orderBy('updated_at', 'desc')->paginate(5);
  978. }
  979. if (request('status') === null && !request('expected')) {
  980. $order = AlbumOrderModel::where('store_id', $storeid)->where('user_id', $userid)->orderBy('updated_at', 'desc')->paginate(5);
  981. }
  982. return $this->api(compact('order'));
  983. } else {
  984. if (request('status') !== null) {
  985. if (request('status') == 8) {
  986. $order = AlbumOrderModel::where('store_id', $storeid)->whereIn('status', [1, 2, 3])->orderBy('updated_at', 'desc')->paginate(5);
  987. } elseif (request('status') == 9) {
  988. $order = AlbumOrderModel::where('store_id', $storeid)->whereIn('status', [3, 4, 5])->orderBy('updated_at', 'desc')->paginate(5);
  989. } else {
  990. $order = AlbumOrderModel::where('store_id', $storeid)->where('status', request('status'))->orderBy('updated_at', 'desc')->paginate(5);
  991. }
  992. }
  993. if (request('expected')) {
  994. $order = AlbumOrderModel::where('store_id', $storeid)
  995. ->where('status', '>', 0)
  996. ->where('status', '<', 5)
  997. ->where(DB::raw("DATEDIFF(NOW(),expected_time)"), '>', 0)
  998. ->orderBy('updated_at', 'desc')->paginate(5);
  999. }
  1000. if (request('status') === null && !request('expected')) {
  1001. $order = AlbumOrderModel::where('store_id', $storeid)->orderBy('updated_at', 'desc')->paginate(5);
  1002. }
  1003. return $this->api($order);
  1004. }
  1005. }
  1006. /**
  1007. * @api {get} /api/furniture/getorderdetail 获取订单详情
  1008. * @apiDescription 获取订单详情
  1009. * @apiGroup Furniture_Service
  1010. * @apiPermission Passport
  1011. * @apiVersion 0.1.0
  1012. * @apiParam {string} store_id
  1013. * @apiParam {string} order_id
  1014. * @apiSuccessExample {json} Success-Response:
  1015. * HTTP/1.1 200 OK
  1016. * {
  1017. * "status": true,
  1018. * "status_code": 0,
  1019. * "message": "",
  1020. * "data": {
  1021. * "order": { //订单详情
  1022. * "id": 1,
  1023. * "sno": "s1001",
  1024. * "qrcode": "qr.png",
  1025. * "status": 1,
  1026. * "category": "冰箱",
  1027. * "type": "s1002",
  1028. * "color": "白色",
  1029. * "question": "问题测试",
  1030. * "customer_name": "wesley",
  1031. * "customer_phone": "18380257014",
  1032. * "customer_address": "成都市新都区",
  1033. * "user_id": 1,
  1034. * "producer_id": null,
  1035. * "packer_id": null,
  1036. * "price": 50,
  1037. * "expected_time": "2018-07-05",
  1038. * "remark": null, //备注
  1039. * "store_id": 1,
  1040. * "deleted_at": null,
  1041. * "created_at": "2018-07-03 17:18:26",
  1042. * "updated_at": "2018-07-05 14:53:42",
  1043. * "pcture": [
  1044. * "1.png",
  1045. * "2.png"
  1046. * ]
  1047. * },
  1048. * "progress": [ //订单进度
  1049. * ...
  1050. * {
  1051. * "created_at": "2018-08-02 17:31:14",
  1052. * "description": "订单已提交,等待审核",
  1053. * "status": 0
  1054. * }
  1055. * ...
  1056. * ],
  1057. * "parts": [ //订单配件
  1058. * ...
  1059. * {
  1060. * "name": "螺丝刀",
  1061. * "count": 1
  1062. * },
  1063. * ...
  1064. * ]
  1065. * }
  1066. * }
  1067. * @apiErrorExample {json} Error-Response:
  1068. * HTTP/1.1 400 Bad Request
  1069. * {
  1070. * "state": false,
  1071. * "code": 1000,
  1072. * "message": "传入参数不正确",
  1073. * "data": null or []
  1074. * }
  1075. * 可能出现的错误代码:
  1076. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1077. */
  1078. public function getOrderDetail(Request $request)
  1079. {
  1080. $validator = Validator::make($request->all(), [
  1081. 'store_id' => 'required',
  1082. 'order_id' => 'required',
  1083. ], [
  1084. 'store_id.required' => '站点信息未知',
  1085. 'order_id.required' => 'order id未知',
  1086. ]);
  1087. if ($validator->fails()) {
  1088. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1089. }
  1090. $user = Auth('api')->user();
  1091. if (!$user) {
  1092. $data = [
  1093. 'code' => 401,
  1094. 'msg' => 'token已过期,请重新登录'
  1095. ];
  1096. return $this->api($data);
  1097. }
  1098. $order = AlbumOrderModel::find(request('order_id'));
  1099. $parts = AlbumPartsModel::where('store_id', request('store_id'))->where('order_id', request('order_id'))
  1100. ->get(['name', 'count']);
  1101. $progress = AlbumProgressModel::where('store_id', request('store_id'))->where('order_id', request('order_id'))->orderBy('created_at', 'asc')->get(['created_at', 'description', 'status']);
  1102. $order->picture = explode(',', $order->picture);
  1103. return $this->api(compact('order', 'progress', 'parts'));
  1104. }
  1105. /**
  1106. * @api {get} /api/furniture/getprogress 订单进度统计
  1107. * @apiDescription 订单进度统计
  1108. * @apiGroup Furniture_Service
  1109. * @apiPermission none
  1110. * @apiVersion 0.1.0
  1111. * @apiParam {string} store_id
  1112. * @apiParam {string} [user_id] (查询用户个人各个订单状态数量时带上此参数)
  1113. * @apiParam {string} [status]( 0:待审核;1:待生产;2:生产中;3:待发货;4:未签收,不填写则返回所有状态下的订单数量)
  1114. * @apiParam {string} [expected] 1:逾期)
  1115. * * @apiSuccessExample {json} Success-Response:
  1116. * HTTP/1.1 200 OK 所有状态统计
  1117. * {
  1118. * "status": true,
  1119. * "status_code": 0,
  1120. * "message": "",
  1121. * "data": {
  1122. * ""count": [
  1123. * {
  1124. * "status": 0, //订单状态
  1125. * "total": 1 //改状态订单数量
  1126. * },
  1127. * {
  1128. * "status": 1,
  1129. * "total": ''
  1130. * },
  1131. * "status": 2,
  1132. * "total": ''
  1133. * },
  1134. * "status": 3,
  1135. * "total": ''
  1136. * },
  1137. * "status": 4,
  1138. * "total": ''
  1139. * },
  1140. * {
  1141. * "expected": 1,
  1142. * "total": 1
  1143. * }
  1144. * ]
  1145. * }
  1146. * }
  1147. *
  1148. * @apiSuccessExample {json} Success-Response:
  1149. * HTTP/1.1 200 OK 具体状态下统计图
  1150. * {
  1151. * "status": true,
  1152. * "status_code": 0,
  1153. * "message": "",
  1154. * "data": {
  1155. * "count": [
  1156. * ...
  1157. * {
  1158. * "customer_name": "", //联系人姓名
  1159. * "days": "" //该状态维持天数
  1160. * }
  1161. * ...
  1162. * ]
  1163. * }
  1164. * }
  1165. * @apiErrorExample {json} Error-Response:
  1166. * HTTP/1.1 400 Bad Request
  1167. * {
  1168. * "state": false,
  1169. * "code": 1000,
  1170. * "message": "传入参数不正确",
  1171. * "data": null or []
  1172. * }
  1173. * 可能出现的错误代码:
  1174. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1175. */
  1176. public function getProgress(Request $request)
  1177. {
  1178. $validator = Validator::make($request->all(), [
  1179. 'store_id' => 'required',
  1180. ], [
  1181. 'store_id.required' => '站点信息未知',
  1182. ]);
  1183. if ($validator->fails()) {
  1184. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1185. }
  1186. $storeid = request('store_id');
  1187. $status = request('status');
  1188. $expected = request('expected');
  1189. $user_id = request('user_id');
  1190. if ($user_id) {
  1191. if ($status === null && !$expected) {
  1192. $count1 = AlbumOrderModel::where('store_id', $storeid)
  1193. ->where('user_id', $user_id)
  1194. ->groupBy('status')
  1195. ->select('status', DB::raw('count(*) as total'))
  1196. ->get()->toArray();
  1197. $count2 = AlbumOrderModel::where('store_id', $storeid)
  1198. ->where('user_id', $user_id)
  1199. ->where('status', '>', 0)
  1200. ->where('status', '<', 5)
  1201. ->where(DB::raw("DATEDIFF(NOW(),expected_time)", '>', 0))
  1202. ->select('id as expected', DB::raw('count(*) as total'))
  1203. ->get()->toArray();
  1204. $count2[0]['expected'] = 1;
  1205. $count = array_merge($count1, $count2);
  1206. }
  1207. if ($status !== null) {
  1208. $count = AlbumOrderModel::where('store_id', $storeid)
  1209. ->where('status', $status)
  1210. ->where('user_id', $user_id)
  1211. ->select('customer_name', 'updated_at')->get();
  1212. foreach ($count as $item) {
  1213. $item->days = Carbon::now()->diffInDays($item->updated_at);
  1214. unset($item->updated_at);
  1215. }
  1216. }
  1217. if ($expected) {
  1218. $count = AlbumOrderModel::where('store_id', $storeid)
  1219. ->where('user_id', $user_id)
  1220. ->where('status', '>', 0)
  1221. ->where('status', '<', 5)
  1222. ->where(DB::raw("DATEDIFF(NOW(),expected_time)"), '>', 0)
  1223. ->select('customer_name', 'updated_at')
  1224. ->get();
  1225. foreach ($count as $item) {
  1226. $item->days = Carbon::now()->diffInDays($item->updated_at);
  1227. unset($item->updated_at);
  1228. }
  1229. }
  1230. } else {
  1231. if ($status === null && !$expected) {
  1232. $count1 = AlbumOrderModel::where('store_id', $storeid)->groupBy('status')->select('status', DB::raw('count(*) as total'))->get()->toArray();
  1233. $count2 = AlbumOrderModel::where('store_id', $storeid)
  1234. ->where('status', '>', 0)
  1235. ->where('status', '<', 5)
  1236. ->where(DB::raw("DATEDIFF(NOW(),expected_time)"), '>', 0)
  1237. ->select('id as expected', DB::raw('count(*) as total'))
  1238. ->get()->toArray();
  1239. $count2[0]['expected'] = 1;
  1240. $count = array_merge($count1, $count2);
  1241. }
  1242. if ($status !== null) {
  1243. $count = AlbumOrderModel::where('store_id', $storeid)->where('status', $status)->select('customer_name', 'updated_at')->get();
  1244. foreach ($count as $item) {
  1245. $item->days = Carbon::now()->diffInDays($item->updated_at);
  1246. unset($item->updated_at);
  1247. }
  1248. }
  1249. if ($expected) {
  1250. $count = AlbumOrderModel::where('store_id', $storeid)
  1251. ->where('status', '>', 0)
  1252. ->where('status', '<', 5)
  1253. ->where(DB::raw("DATEDIFF(NOW(),expected_time)"), '>', 0)
  1254. ->select('customer_name', 'updated_at')->get();
  1255. foreach ($count as $item) {
  1256. $item->days = Carbon::now()->diffInDays($item->updated_at);
  1257. unset($item->updated_at);
  1258. }
  1259. }
  1260. }
  1261. return $this->api(compact('count'));
  1262. }
  1263. /**
  1264. * @api {get} /api/furniture/getreviewcount 评价统计
  1265. * @apiDescription 评价统计
  1266. * @apiGroup Furniture_Service
  1267. * @apiPermission none
  1268. * @apiVersion 0.1.0
  1269. * @apiParam {string} store_id
  1270. * @apiParam {string} [days](必填 0:今天;7:7天内;30:30天内
  1271. * * @apiSuccessExample {json} Success-Response:
  1272. * HTTP/1.1 200 OK 所有状态统计
  1273. * {
  1274. * "status": true,
  1275. * "status_code": 0,
  1276. * "message": "",
  1277. * "data": {
  1278. * "verifier": [ //客服部
  1279. * {
  1280. * "verifier_review": 0, 评价等级:0:好评 1:中评 2:差评
  1281. * "verifier": 7 评价数量
  1282. * },
  1283. * {
  1284. * "verifier_review": 1,
  1285. * "verifier": 5
  1286. * },
  1287. * ],
  1288. * "producer": [ //生产部
  1289. * {
  1290. * "producer_review": 0,
  1291. * "producer": 1
  1292. * },
  1293. * ...
  1294. * ],
  1295. * "packer": [ //包装部
  1296. * {
  1297. * "producer_review": 0,
  1298. * "producer": 1
  1299. * },
  1300. * ...
  1301. * ]
  1302. * }
  1303. * }
  1304. *
  1305. * @apiErrorExample {json} Error-Response:
  1306. * HTTP/1.1 400 Bad Request
  1307. * {
  1308. * "state": false,
  1309. * "code": 1000,
  1310. * "message": "传入参数不正确",
  1311. * "data": null or []
  1312. * }
  1313. * 可能出现的错误代码:
  1314. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1315. */
  1316. public function getReviewCount(Request $request)
  1317. {
  1318. $validator = Validator::make($request->all(), [
  1319. 'store_id' => 'required',
  1320. ], [
  1321. 'store_id.required' => '站点信息未知',
  1322. ]);
  1323. if ($validator->fails()) {
  1324. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1325. }
  1326. $storeid = request('store_id');
  1327. $days = request('days') ? request('days') : 0;
  1328. //客服部
  1329. $verifier = AlbumReviewModel::where('store_id', $storeid)->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)->groupBy('verifier_review')->select(DB::raw('verifier_review,count(*) as verifier'))->orderBy('verifier_review', 'asc')->get()->toArray();
  1330. //生产部
  1331. $producer = AlbumReviewModel::where('store_id', $storeid)->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)->groupBy('producer_review')->select(DB::raw('producer_review,count(*) as producer'))->orderBy('producer_review', 'asc')->get()->toArray();
  1332. //包装部
  1333. $packer = AlbumReviewModel::where('store_id', $storeid)->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)->groupBy('packer_review')->select(DB::raw('packer_review,count(*) as packer'))->orderBy('packer_review', 'asc')->get()->toArray();
  1334. return $this->api(compact('verifier', 'producer', 'packer'));
  1335. }
  1336. /**
  1337. * @api {get} /api/furniture/ordercount 按产品/品类统计
  1338. * @apiDescription 按产品/品类统计
  1339. * @apiGroup Furniture_Service
  1340. * @apiPermission none
  1341. * @apiVersion 0.1.0
  1342. * @apiParam {string} store_id
  1343. * @apiParam {string} [type] 按产品统计,可选值:1
  1344. * @apiParam {string} [category] 按品类统计,与type二选一,不能与type同时传值。可选值:1(所有品类)具体品类的值(统计具体品类)
  1345. * @apiParam {string} [days] 可选:0,7,30
  1346. * * @apiSuccessExample {json} Success-Response:
  1347. * HTTP/1.1 200 OK 所有状态统计
  1348. * {
  1349. * "status": true,
  1350. * "status_code": 0,
  1351. * "message": "",
  1352. * "data": {
  1353. * ...
  1354. * {
  1355. * "days": "2018-07-03", //日期
  1356. * "count": 2, //数量
  1357. * "category": "冰箱", //品类
  1358. * "type": "s1002" //产品型号
  1359. * },
  1360. * ...
  1361. * }
  1362. * }
  1363. *
  1364. * @apiErrorExample {json} Error-Response:
  1365. * HTTP/1.1 400 Bad Request
  1366. * {
  1367. * "state": false,
  1368. * "code": 1000,
  1369. * "message": "传入参数不正确",
  1370. * "data": null or []
  1371. * }
  1372. * 可能出现的错误代码:
  1373. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1374. */
  1375. public function orderCount(Request $request)
  1376. {
  1377. $validator = Validator::make($request->all(), [
  1378. 'store_id' => 'required',
  1379. ], [
  1380. 'store_id.required' => '站点信息未知',
  1381. ]);
  1382. if ($validator->fails()) {
  1383. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1384. }
  1385. $storeid = request('store_id');
  1386. $type = request('type');
  1387. $category = request('category');
  1388. $days = request('days') ? request('days') : 0;
  1389. if ($type) {
  1390. if ($type == 1) {
  1391. $order = AlbumOrderModel::where('store_id', $storeid)
  1392. ->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)
  1393. ->where('status', '>', 0)
  1394. ->where('status', '<', 7)
  1395. ->groupBy('days', 'type')
  1396. ->select(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as days,count('id') as count,'type',category"), 'type')
  1397. ->get();
  1398. } else {
  1399. $order = AlbumOrderModel::where('store_id', $storeid)
  1400. ->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)
  1401. ->where('status', '>', 0)
  1402. ->where('status', '<', 7)
  1403. ->where('type', $type)
  1404. ->groupBy('days', 'type')
  1405. ->select(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as days,count('id') as count,'type',category"), 'type')
  1406. ->get();
  1407. }
  1408. }
  1409. if ($category) {
  1410. if ($category == 1) {
  1411. $order = AlbumOrderModel::where('store_id', $storeid)
  1412. ->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)
  1413. ->where('status', '>', 0)
  1414. ->where('status', '<', 7)
  1415. ->groupBy('days', 'category')
  1416. ->select(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as days,count('id') as count,category,type"), 'type')
  1417. ->get();
  1418. } else {
  1419. $order = AlbumOrderModel::where('store_id', $storeid)
  1420. ->where(DB::raw("DATEDIFF(NOW(),created_at)"), '<=', $days)
  1421. ->where('status', '>', 0)
  1422. ->where('status', '<', 7)
  1423. ->where('category', $category)
  1424. ->groupBy('days', 'category')
  1425. ->select(DB::raw("DATE_FORMAT(created_at,'%Y-%m-%d') as days,count('id') as count,category,type"), 'type')
  1426. ->get();
  1427. }
  1428. }
  1429. return $this->api($order);
  1430. }
  1431. /**
  1432. * @api {get} /api/furniture/searchlist 产品订单搜索列表页
  1433. * @apiDescription 产品订单搜索列表页
  1434. * @apiGroup Furniture_Service
  1435. * @apiPermission none
  1436. * @apiVersion 0.1.0
  1437. * @apiParam {string} store_id
  1438. * @apiParam {string} [keyword] 搜索关键字
  1439. * * @apiSuccessExample {json} Success-Response:
  1440. * HTTP/1.1 200 OK
  1441. * {
  1442. * "status": true,
  1443. * "status_code": 0,
  1444. * "message": "",
  1445. * "data": {
  1446. * "current_page": 1,
  1447. * "data": [
  1448. * ...
  1449. * {
  1450. * "id": 1,
  1451. * "sno": "s1001",
  1452. * "qrcode": "qr.png",
  1453. * "status": 1,
  1454. * "category": "冰箱",
  1455. * "type": "s1002",
  1456. * "color": "白色",
  1457. * "picture": "1.ipg",
  1458. * "question": "问题测试",
  1459. * "customer_name": "wesley",
  1460. * "customer_phone": "18380257014",
  1461. * "customer_address": "成都市新都区",
  1462. * "user_id": 1,
  1463. * "producer_id": null,
  1464. * "packer_id": null,
  1465. * "price": 50,
  1466. * "expected_time": "2018-07-05",
  1467. * "remark": null,
  1468. * "store_id": 1,
  1469. * "created_at": "2018-07-03 17:18:26",
  1470. * "updated_at": "2018-07-05 14:53:42"
  1471. * }
  1472. * ...
  1473. * ],
  1474. * "first_page_url": "http://s1.xcx.com/api/furniture/getorder?page=1",
  1475. * "from": 1,
  1476. * "last_page": 1,
  1477. * "last_page_url": "http://s1.xcx.com/api/furniture/getorder?page=1",
  1478. * "next_page_url": null,
  1479. * "path": "http://s1.xcx.com/api/furniture/getorder",
  1480. * "per_page": 5,
  1481. * "prev_page_url": null,
  1482. * "to": 2,
  1483. * "total": 2 //订单数量
  1484. * }
  1485. * }
  1486. * @apiErrorExample {json} Error-Response:
  1487. * HTTP/1.1 400 Bad Request
  1488. * {
  1489. * "state": false,
  1490. * "code": 1000,
  1491. * "message": "传入参数不正确",
  1492. * "data": null or []
  1493. * }
  1494. * 可能出现的错误代码:
  1495. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1496. */
  1497. public function searchList(Request $request)
  1498. {
  1499. $validator = Validator::make($request->all(), [
  1500. 'store_id' => 'required',
  1501. ], [
  1502. 'store_id.required' => '站点信息未知',
  1503. ]);
  1504. if ($validator->fails()) {
  1505. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1506. }
  1507. $storeid = request('store_id');
  1508. $keyword = request('keyword');
  1509. if ($keyword) {
  1510. $order = AlbumOrderModel::where('store_id', $storeid)
  1511. ->where(function ($query) use ($keyword) {
  1512. $query->where('type', 'like', '%' . $keyword . '%')
  1513. ->orwhere('sno', 'like', '%' . $keyword . '%')
  1514. ->orwhere('customer_name', 'like', '%' . $keyword . '%')
  1515. ->orwhere('customer_phone', 'like', '%' . $keyword . '%');
  1516. })
  1517. ->orderBy('updated_at', 'desc')
  1518. ->paginate(5);
  1519. } else {
  1520. $order = AlbumOrderModel::where('store_id', $storeid)
  1521. ->orderBy('updated_at', 'desc')
  1522. ->paginate(5);
  1523. }
  1524. return $this->api($order);
  1525. }
  1526. /**
  1527. * @api {post} /api/furniture/addreview 添加评论
  1528. * @apiDescription 添加评论
  1529. * @apiGroup Furniture_Service
  1530. * @apiPermission Passport
  1531. * @apiVersion 0.1.0
  1532. * @apiParam {string} store_id
  1533. * @apiParam {int} order_id
  1534. * @apiParam {int} verifier_review 客服部评论:0:好评;1:中评:2:差评
  1535. * @apiParam {int} producer_review 生产部部评论:0:好评;1:中评:2:差评
  1536. * @apiParam {int} packer_review 包装部评论:0:好评;1:中评:2:差评
  1537. * @apiParam {int} [description] 评论描述
  1538. * @apiParam {int} [picture] 图片
  1539. * * @apiSuccessExample {json} Success-Response:
  1540. * HTTP/1.1 200 OK 添加评论成功
  1541. * {
  1542. * "status": true,
  1543. * "status_code": 0,
  1544. * "message": "",
  1545. * "data": {
  1546. * "store_id": "1",
  1547. * "verifier_review": "0",
  1548. * "producer_review": "0",
  1549. * "packer_review": "1",
  1550. * "order_id": "1",
  1551. * "updated_at": "2018-07-26 15:03:33",
  1552. * "created_at": "2018-07-26 15:03:33",
  1553. * "id": 5
  1554. * }
  1555. * }
  1556. *
  1557. * @apiErrorExample {json} Error-Response:
  1558. * HTTP/1.1 400 Bad Request
  1559. * {
  1560. * "state": false,
  1561. * "code": 1000,
  1562. * "message": "传入参数不正确",
  1563. * "data": null or []
  1564. * }
  1565. * 可能出现的错误代码:
  1566. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1567. */
  1568. public function addReview(Request $request)
  1569. {
  1570. $validator = Validator::make($request->all(), [
  1571. 'store_id' => 'required',
  1572. 'order_id' => 'required',
  1573. 'verifier_review' => 'required',
  1574. 'producer_review' => 'required',
  1575. 'packer_review' => 'required',
  1576. ], [
  1577. 'store_id.required' => '站点信息未知',
  1578. 'order_id.required' => '未知的订单',
  1579. 'verifier_review.required' => '客服部评论未填',
  1580. 'producer_review.required' => '生产部评论未填',
  1581. 'packer_review.required' => '包装部评论未填',
  1582. ]);
  1583. if ($validator->fails()) {
  1584. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1585. }
  1586. $user = Auth('api')->user();
  1587. if (!$user) {
  1588. $data = [
  1589. 'code' => 401,
  1590. 'msg' => 'token已过期,请重新登录'
  1591. ];
  1592. return $this->api($data);
  1593. }
  1594. $data = $request->all();
  1595. $order = $order = AlbumOrderModel::find(request('order_id'));
  1596. $order->status = 6;
  1597. $order->save();
  1598. if (isset($data['picture'])) {
  1599. $data['picture'] = implode(',', $data['picture']);
  1600. }
  1601. $review = AlbumReviewModel::create($data);
  1602. return $this->api($review);
  1603. }
  1604. /**
  1605. * @api {post} /api/furniture/updatestatus 更新订单状态
  1606. * @apiDescription 更新订单状态
  1607. * @apiGroup Furniture_Service
  1608. * @apiPermission Passport
  1609. * @apiVersion 0.1.0
  1610. * @apiParam {string} store_id
  1611. * @apiParam {int} order_id
  1612. * @apiParam {int} status 2:开始生产 3:生产完毕并入库 4:发货 5:确认收货 7:取消订单
  1613. * @apiParam {int} [remark] 备注,发货时可携带此参数
  1614. * * @apiSuccessExample {json} Success-Response:
  1615. * HTTP/1.1 200 OK 更新状态成功
  1616. * {
  1617. * "status": true,
  1618. * "status_code": 0,
  1619. * "message": "",
  1620. * "data": {
  1621. * "ok":1
  1622. * }
  1623. * }
  1624. *
  1625. * @apiErrorExample {json} Error-Response:
  1626. * HTTP/1.1 400 Bad Request
  1627. * {
  1628. * "state": false,
  1629. * "code": 1000,
  1630. * "message": "传入参数不正确",
  1631. * "data": null or []
  1632. * }
  1633. * 可能出现的错误代码:
  1634. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1635. */
  1636. public function updateStatus(Request $request)
  1637. {
  1638. $validator = Validator::make($request->all(), [
  1639. 'store_id' => 'required',
  1640. 'order_id' => 'required',
  1641. 'status' => 'required|regex:/[23457]/',
  1642. ], [
  1643. 'store_id.required' => '站点信息未知',
  1644. 'order_id.required' => 'order id未知',
  1645. 'status.required' => 'status未知',
  1646. 'status.regex' => '请填写正确的订单状态',
  1647. ]);
  1648. if ($validator->fails()) {
  1649. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1650. }
  1651. $user = Auth('api')->user();
  1652. if (!$user) {
  1653. $data = [
  1654. 'code' => 401,
  1655. 'msg' => 'token已过期,请重新登录'
  1656. ];
  1657. return $this->api($data);
  1658. }
  1659. $storeid = request('store_id');
  1660. $orderid = request('order_id');
  1661. $status = request('status');
  1662. $remark = request('remark');
  1663. $order = AlbumOrderModel::find($orderid);
  1664. $order->status = $status;
  1665. if ($remark) {
  1666. $order->remark = $remark;
  1667. }
  1668. if ($status == 2 || $status == 3) {
  1669. $order->producer_id = $user->id;
  1670. }
  1671. if ($status == 4) {
  1672. $order->packer_id = $user->id;
  1673. }
  1674. $ok = $order->save();
  1675. $this->addProgress($status, $storeid, $orderid);
  1676. return $this->api(compact('ok'));
  1677. }
  1678. /**
  1679. * @api {post} /api/furniture/getphonenumber 获取手机号
  1680. * @apiDescription 获取手机号
  1681. * @apiGroup Furniture_Service
  1682. * @apiPermission none
  1683. * @apiVersion 0.1.0
  1684. * @apiParam {string} store_id
  1685. * @apiParam {string} session_key
  1686. * @apiParam {string} iv
  1687. * @apiParam {string} encryptData
  1688. * @apiSuccessExample {json} Success-Response:
  1689. * HTTP/1.1 200 OK
  1690. * {
  1691. * "status": true,
  1692. * "status_code": 0,
  1693. * "message": "",
  1694. * "data": {
  1695. * "decryptedData": [
  1696. *
  1697. * ]
  1698. *
  1699. * }
  1700. *
  1701. * }
  1702. * @apiErrorExample {json} Error-Response:
  1703. * HTTP/1.1 400 Bad Request
  1704. * {
  1705. * "state": false,
  1706. * "code": 1000,
  1707. * "message": "传入参数不正确",
  1708. * "data": null or []
  1709. * }
  1710. * 可能出现的错误代码:
  1711. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1712. */
  1713. public function getPhoneNumber(Request $request)
  1714. {
  1715. $validator = Validator::make($request->all(), [
  1716. 'store_id' => 'required',
  1717. 'session_key' => 'required',
  1718. 'iv' => 'required',
  1719. 'encryptData' => 'required',
  1720. ], [
  1721. 'store_id.required' => '站点信息未知',
  1722. 'session_key.required' => 'session_key未知',
  1723. 'iv.required' => 'iv未知',
  1724. 'encryptData.required' => 'encryptData未知',
  1725. ]);
  1726. if ($validator->fails()) {
  1727. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1728. }
  1729. $session_key = $request->get('session_key');
  1730. $iv = $request->get('iv');
  1731. $encryptData = $request->get('encryptData');
  1732. $storeid = $request->get('store_id');
  1733. $this->wechat_app = AlbumManufacturerModel::where('store_id', $storeid)->first();
  1734. $config = [
  1735. 'app_id' => $this->wechat_app->service_app_id,
  1736. 'secret' => $this->wechat_app->service_app_secret,
  1737. // 下面为可选项
  1738. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  1739. 'response_type' => 'array',
  1740. ];
  1741. $app = Factory::miniProgram($config);
  1742. $decryptedData = $app->encryptor->decryptData($session_key, $iv, $encryptData);
  1743. return $this->api(compact('decryptedData'));
  1744. }
  1745. /**
  1746. * @api {post} /api/furniture/printorder 打印订单
  1747. * @apiDescription 打印订单
  1748. * @apiGroup Furniture_Service
  1749. * @apiPermission none
  1750. * @apiVersion 0.1.0
  1751. * @apiParam {string} store_id
  1752. * @apiParam {string} order_id
  1753. * @apiParam {int} role 1:生产部
  1754. * @apiSuccessExample {json} Success-Response:
  1755. * HTTP/1.1 200 OK
  1756. * {
  1757. * "status": true,
  1758. * "status_code": 0,
  1759. * "message": "",
  1760. * "data": {
  1761. * "code": 200,
  1762. * "msg": "打印成功!"
  1763. * }
  1764. * }
  1765. * @apiErrorExample {json} Error-Response:
  1766. * HTTP/1.1 400 Bad Request
  1767. * {
  1768. * "state": false,
  1769. * "code": 1000,
  1770. * "message": "传入参数不正确",
  1771. * "data": null or []
  1772. * }
  1773. * 可能出现的错误代码:
  1774. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1775. */
  1776. public function printOrder(Request $request)
  1777. {
  1778. header("Content-type: text/html; charset=utf-8");
  1779. $validator = Validator::make($request->all(), [
  1780. 'store_id' => 'required',
  1781. 'order_id' => 'required',
  1782. ], [
  1783. 'store_id.required' => '站点信息未知',
  1784. 'order_id.required' => 'order_id信息未知',
  1785. ]);
  1786. if ($validator->fails()) {
  1787. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1788. }
  1789. $role = $request->get('role') ? $request->get('role') : 2;
  1790. $order = AlbumOrderModel::find(request('order_id'));
  1791. $filename = explode('/', $order->qrcode);
  1792. $filename = end($filename);
  1793. $qrcode = public_path() . '/download/' . $filename;
  1794. $image = new ZBarCodeImage($qrcode);
  1795. $scanner = new ZBarCodeScanner();
  1796. $qrcodedata = $scanner->scan($image);
  1797. $qrcodetext = $qrcodedata[0]['data'];
  1798. // $QrReader = new \QrReader($qrcode);
  1799. // $qrcodetext = $QrReader->text();
  1800. $content = "";
  1801. if ($role == 2) {
  1802. $content .= "--------------------------------<BR>";
  1803. $content .= "<B>订单编号 #" . $order->sno . " </B><BR><BR>";
  1804. $content .= "<B>下单时间:" . $order->created_at . "</B><BR><BR>";
  1805. $content .= "<B>产品型号:" . $order->type . "</B><BR><BR>";
  1806. $content .= "<B>修理费:" . $order->price . "</B><BR><BR>";
  1807. $content .= "--------------------------------<BR>";
  1808. $content .= "<B>送货地点:" . $order->customer_address . "</B><BR><BR>";
  1809. $content .= "<B>联系电话:" . $order->customer_phone . "</B><BR><BR>";
  1810. $content .= "<B>联系人:" . $order->customer_name . "</B><BR><BR>";
  1811. }
  1812. if ($order->remark && $role == 2) {
  1813. $content .= "<B>备注:" . $order->remark . "</B><BR>";
  1814. }
  1815. \Log::info($qrcode);
  1816. \Log::info($qrcodetext);
  1817. if ($role == 1) {
  1818. $content .= "<CB>客户:" . $order->customer_name . "</CB><BR>";
  1819. }
  1820. $content .= "<QR>" . $qrcodetext . "</QR><BR>";
  1821. $setting = AlbumManufacturerModel::where('store_id', request('store_id'))->first();
  1822. if($setting->print_type == 2){
  1823. $res = $this->print_365($setting->print_no, $setting->print_key,$content, 1);
  1824. }else{
  1825. $res = $this->wp_print($setting->print_no, $content, 1);
  1826. }
  1827. if ($res) {
  1828. $data = [
  1829. 'code' => 200,
  1830. 'msg' => '打印成功!'
  1831. ];
  1832. return $this->api($data);
  1833. } else {
  1834. $data = [
  1835. 'code' => 4,
  1836. 'msg' => '打印机连接失败!'
  1837. ];
  1838. return $this->api($data);
  1839. }
  1840. }
  1841. function print_365($printer_sn,$print_key, $orderInfo, $times){
  1842. $selfMessage = array(
  1843. 'deviceNo' => $printer_sn,
  1844. 'printContent' => $orderInfo,
  1845. 'key' => $print_key,
  1846. 'times' => $times
  1847. );
  1848. $url = "http://open.printcenter.cn:8080/addOrder";
  1849. $options = array(
  1850. 'http' => array(
  1851. 'header' => "Content-type: application/x-www-form-urlencoded ",
  1852. 'method' => 'POST',
  1853. 'content' => http_build_query($selfMessage),
  1854. ),
  1855. );
  1856. $context = stream_context_create($options);
  1857. $result = file_get_contents($url, false, $context);
  1858. $res = json_decode($result);
  1859. if(isset($res->responseCode) && $res->responseCode === 0){
  1860. return true;
  1861. }else{
  1862. return false;
  1863. }
  1864. }
  1865. function wp_print($printer_sn, $orderInfo, $times)
  1866. {
  1867. $user = '1170640404@qq.com';
  1868. $ukey = 'ECfrLVsrd9Wq22zR';
  1869. $stime = time();
  1870. $content = array(
  1871. 'user' => $user,
  1872. 'stime' => $stime,
  1873. 'sig' => sha1($user . $ukey . $stime),
  1874. 'apiname' => 'Open_printMsg',
  1875. 'sn' => $printer_sn,
  1876. 'content' => $orderInfo,
  1877. 'times' => $times//打印次数
  1878. );
  1879. $client = new \HttpClient('api.feieyun.cn', 80);
  1880. if (!$client->post('/Api/Open/', $content)) {
  1881. \Log::info($client->getContent());
  1882. return false;
  1883. } else {
  1884. \Log::info($client->getContent());
  1885. return true;
  1886. }
  1887. }
  1888. /**
  1889. * @api {post} /api/furniture/saveformid 保存formid
  1890. * @apiDescription 保存formid
  1891. * @apiGroup Furniture_Service
  1892. * @apiPermission none
  1893. * @apiVersion 0.1.0
  1894. * @apiParam {string} store_id
  1895. * @apiParam {string} openid
  1896. * @apiParam {string} formid
  1897. * @apiSuccessExample {json} Success-Response:
  1898. * HTTP/1.1 200 OK
  1899. * {
  1900. * "status": true,
  1901. * "status_code": 0,
  1902. * "message": "",
  1903. * "data": {
  1904. * "code": 200,
  1905. * "msg": "添加成功"
  1906. * }
  1907. * }
  1908. * @apiErrorExample {json} Error-Response:
  1909. * HTTP/1.1 400 Bad Request
  1910. * {
  1911. * "state": false,
  1912. * "code": 1000,
  1913. * "message": "传入参数不正确",
  1914. * "data": null or []
  1915. * }
  1916. * 可能出现的错误代码:
  1917. * 1000 CLIENT_WRONG_PARAMS 传入参数不正确
  1918. */
  1919. public function saveFormId(Request $request)
  1920. {
  1921. $validator = Validator::make($request->all(), [
  1922. 'store_id' => 'required',
  1923. 'openid' => 'required',
  1924. 'formid' => 'required',
  1925. ], [
  1926. 'store_id.required' => '站点信息未知',
  1927. 'formid.required' => 'formid未知',
  1928. 'openid.required' => 'openid未知',
  1929. ]);
  1930. if ($validator->fails()) {
  1931. return $this->validatorError($validator->messages()->all(), ErrorCode::CLIENT_WRONG_PARAMS, '');
  1932. }
  1933. $data = $request->all();
  1934. $res = FurnitureFormidModel::create($data);
  1935. if ($res) {
  1936. $data = [
  1937. 'code' => 200,
  1938. 'msg' => '添加成功'
  1939. ];
  1940. }
  1941. return $this->api($data);
  1942. }
  1943. public function getQrcode($store_id, $id)
  1944. {
  1945. $this->wechat_app = AlbumManufacturerModel::where('store_id', $store_id)->first();
  1946. $config = [
  1947. 'app_id' => $this->wechat_app->service_app_id,
  1948. 'secret' => $this->wechat_app->service_app_secret,
  1949. // 下面为可选项
  1950. // 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
  1951. 'response_type' => 'array',
  1952. ];
  1953. $app = Factory::miniProgram($config);
  1954. $response = $app->app_code->getQrCode('pages/search/search?order_id=' . $id,400);
  1955. $path = public_path() . '/download';
  1956. $qrcode = $response->save($path, $id);
  1957. $real_path = $path .'/'. $qrcode;
  1958. Image::make($real_path)->crop(423, 415 , 0 , 0)->save($real_path);
  1959. if ($qrcode) {
  1960. $qrcode = env('APP_URL') . '/download/' . $id . '.jpg';
  1961. $order = AlbumOrderModel::find($id);
  1962. $order->qrcode = $qrcode;
  1963. $order->save();
  1964. return true;
  1965. } else {
  1966. return false;
  1967. }
  1968. }
  1969. public function addProgress($status, $store_id, $order_id)
  1970. {
  1971. $data = [
  1972. 'status' => $status,
  1973. 'order_id' => $order_id,
  1974. 'store_id' => $store_id
  1975. ];
  1976. if ($status == 2) {
  1977. $data['description'] = '订单已开始生产';
  1978. }
  1979. if ($status == 3) {
  1980. $data['description'] = '完成生产,订单已下发到包装部,等待发货';
  1981. }
  1982. if ($status == 4) {
  1983. $data['description'] = '包装部已发货,请等待签收';
  1984. }
  1985. if ($status == 5) {
  1986. $data['description'] = '已签收,感谢您选择本公司产品!';
  1987. }
  1988. if ($status == 6) {
  1989. $data['description'] = '已评价';
  1990. }
  1991. return AlbumProgressModel::create($data);
  1992. }
  1993. }