FurnitureController.php 94 KB

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