FurnitureController.php 94 KB

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