OriginaController.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. <?php
  2. namespace Modules\Manage\Controllers;
  3. use App\Constants\CommonConstant;
  4. use App\Repositories\Criterias\GoodsAssessCriteria;
  5. use App\Repositories\Criterias\GoodsCriteria;
  6. use App\Repositories\Criterias\OrderLimitCriteria;
  7. use App\Repositories\Criterias\OriginalClassCriteria;
  8. use App\Repositories\Criterias\OriginalOrderCriteria;
  9. use App\Repositories\Criterias\ShopsCriteria;
  10. use App\Repositories\Criterias\UserShippingAddressCriterias;
  11. use App\Repositories\GoodsAssessRepository;
  12. use App\Repositories\OriginalCategoryRepository;
  13. use App\Repositories\OriginalClassRepository;
  14. use App\Repositories\OriginalOrderRepository;
  15. use App\Repositories\OriginalRepository;
  16. use App\Repositories\ShopsRepository;
  17. use App\Repositories\UserRepository;
  18. use App\Repositories\UserShippingAddressRepository;
  19. use Hyperf\Validation\Contract\ValidatorFactoryInterface;
  20. use Modules\Manage\Responses\CommonPagesResponse;
  21. use Modules\Manage\Responses\OriginaAssessListsResponse;
  22. use Modules\Manage\Responses\OriginaGoodsListsResponse;
  23. use Modules\Manage\Responses\OriginaOrderListsResponse;
  24. use Modules\Manage\Responses\PaymentSuccessUidResponse;
  25. class OriginaController extends BaseController
  26. {
  27. /**
  28. * 分类列表
  29. *
  30. * @param ValidatorFactoryInterface $validatorFactory
  31. * @return mixed|CommonPagesResponse
  32. */
  33. public function categoryLists(ValidatorFactoryInterface $validatorFactory)
  34. {
  35. $inputData = $this->getJsonData();
  36. $rules = [
  37. 'page' => 'nullable|integer',
  38. 'page_size' => 'nullable|integer',
  39. 'sttaus' => 'nullable|string',
  40. 'name' => 'nullable|string',
  41. ];
  42. $validator = $validatorFactory->make($inputData, $rules);
  43. if ($validator->fails()) {
  44. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  45. return json_fail($validator->errors()->first());
  46. }
  47. $orders = [
  48. ['created_at', 'DESC'],
  49. ];
  50. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  51. if ($pageSize > 500) {
  52. $pageSize = CommonConstant::PAGE_SIZE;
  53. }
  54. $page = format_page($inputData['page'] ?? 1);
  55. $res = make(OriginalClassRepository::class)->pushCriteria(new OriginalClassCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  56. return new CommonPagesResponse($res);
  57. }
  58. /**
  59. * 添加分类
  60. *
  61. * @param ValidatorFactoryInterface $validatorFactory
  62. * @return mixed|PaymentSuccessUidResponse
  63. */
  64. public function categoryAdd(ValidatorFactoryInterface $validatorFactory)
  65. {
  66. $inputData = $this->getJsonData();
  67. $rules = [
  68. 'name' => 'required|string',
  69. 'status' => 'required|in:1,2',
  70. 'type' => 'required|in:1,2',
  71. 'sort' => 'required|integer',
  72. ];
  73. $validator = $validatorFactory->make($inputData, $rules);
  74. if ($validator->fails()) {
  75. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  76. return json_fail($validator->errors()->first());
  77. }
  78. $setarr = [
  79. 'name' => $inputData['name'],
  80. 'status' => $inputData['status'],
  81. 'type' => $inputData['type'],
  82. 'sort' => $inputData['sort'],
  83. ];
  84. $result = make(OriginalClassRepository::class)->create($setarr);
  85. if (!$result) {
  86. return json_fail('添加失败');
  87. } else {
  88. $logSubject = '添加一个原味分类,分类名字:' . $inputData['name'];
  89. $logSvalue = $result->uid;
  90. $logDbData = [
  91. 'after_items' => [
  92. $result->toArray(),
  93. ],
  94. 'before_items' => [],
  95. ];
  96. $this->log($logSubject, $logSvalue, $logDbData);
  97. return new PaymentSuccessUidResponse($result->uid);
  98. }
  99. }
  100. /**
  101. * 修改分类
  102. *
  103. * @param ValidatorFactoryInterface $validatorFactory
  104. * @return mixed|PaymentSuccessUidResponse
  105. */
  106. public function categoryEdit(ValidatorFactoryInterface $validatorFactory)
  107. {
  108. $inputData = $this->getJsonData();
  109. $rules = [
  110. 'name' => 'nullable|string',
  111. 'status' => 'nullable|in:1,2',
  112. 'type' => 'nullable|in:1,2',
  113. 'sort' => 'nullable|integer',
  114. 'uid' => 'required|string',
  115. ];
  116. $validator = $validatorFactory->make($inputData, $rules);
  117. if ($validator->fails()) {
  118. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  119. return json_fail($validator->errors()->first());
  120. }
  121. $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
  122. if (!$categoryInfo) {
  123. return json_fail('该类型不存在!');
  124. }
  125. $oldCategoryInfo = clone $categoryInfo;
  126. if (!empty($inputData['name'])) {
  127. $categoryInfo->name = $inputData['name'];
  128. }
  129. if (!empty($inputData['status'])) {
  130. $categoryInfo->status = $inputData['status'];
  131. }
  132. if (!empty($inputData['type'])) {
  133. $categoryInfo->type = $inputData['type'];
  134. }
  135. if (!empty($inputData['sort'])) {
  136. $categoryInfo->sort = $inputData['sort'];
  137. }
  138. $result = $categoryInfo->save();
  139. if (!$result) {
  140. return json_fail('修改失败');
  141. } else {
  142. $logSubject = '修改一个原味分类,名字:' . $oldCategoryInfo->name;
  143. $logSvalue = $oldCategoryInfo->uid;
  144. $logDbData = [
  145. 'after_items' => [
  146. $categoryInfo->toArray(),
  147. ],
  148. 'before_items' => [
  149. $oldCategoryInfo->toArray(),
  150. ],
  151. ];
  152. $this->log($logSubject, $logSvalue, $logDbData);
  153. return new PaymentSuccessUidResponse($categoryInfo->uid);
  154. }
  155. }
  156. /**
  157. * 删除分类
  158. *
  159. * @param ValidatorFactoryInterface $validatorFactory
  160. * @return mixed|PaymentSuccessUidResponse
  161. */
  162. public function categoryDelete(ValidatorFactoryInterface $validatorFactory)
  163. {
  164. $inputData = $this->getJsonData();
  165. $rules = [
  166. 'uid' => 'required|string',
  167. ];
  168. $validator = $validatorFactory->make($inputData, $rules);
  169. if ($validator->fails()) {
  170. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  171. return json_fail($validator->errors()->first());
  172. }
  173. $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
  174. if (!$categoryInfo) {
  175. return json_fail('该类型不存在!');
  176. }
  177. $oldCategoryInfo = clone $categoryInfo;
  178. $result = $categoryInfo->delete();
  179. if (!$result) {
  180. return json_fail('删除失败');
  181. } else {
  182. $logSubject = '删除一个类原味分类,名字:' . $oldCategoryInfo->name;
  183. $logSvalue = $oldCategoryInfo->manager_id;
  184. $logDbData = [
  185. 'after_items' => [
  186. ],
  187. 'before_items' => [
  188. $oldCategoryInfo->toArray(),
  189. ],
  190. ];
  191. $this->log($logSubject, $logSvalue, $logDbData);
  192. return new PaymentSuccessUidResponse($inputData['uid']);
  193. }
  194. }
  195. /**
  196. * 评价列表
  197. *
  198. * @param ValidatorFactoryInterface $validatorFactory
  199. * @return mixed|void
  200. */
  201. public function assessLists(ValidatorFactoryInterface $validatorFactory)
  202. {
  203. $inputData = $this->getJsonData();
  204. $rules = [
  205. 'page' => 'nullable|integer',
  206. 'page_size' => 'nullable|integer',
  207. 'buy_uid' => 'nullable|string',
  208. 'goods_name' => 'nullable|string',
  209. ];
  210. $validator = $validatorFactory->make($inputData, $rules);
  211. if ($validator->fails()) {
  212. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  213. return json_fail($validator->errors()->first());
  214. }
  215. $orders = [
  216. ['created_at', 'DESC'],
  217. ];
  218. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  219. if ($pageSize > 500) {
  220. $pageSize = CommonConstant::PAGE_SIZE;
  221. }
  222. $page = format_page($inputData['page'] ?? 1);
  223. $res = make(GoodsAssessRepository::class)->pushCriteria(new GoodsAssessCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  224. return new OriginaAssessListsResponse($res);
  225. }
  226. /**
  227. * 删除评论
  228. *
  229. * @param ValidatorFactoryInterface $validatorFactory
  230. * @return mixed|PaymentSuccessUidResponse
  231. */
  232. public function assessDelete(ValidatorFactoryInterface $validatorFactory)
  233. {
  234. $inputData = $this->getJsonData();
  235. $rules = [
  236. 'uid' => 'nullable|string',
  237. ];
  238. $validator = $validatorFactory->make($inputData, $rules);
  239. if ($validator->fails()) {
  240. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  241. return json_fail($validator->errors()->first());
  242. }
  243. $goodsAssessInfo = make(GoodsAssessRepository::class)->findBy('uid', $inputData['uid']);
  244. if (!$goodsAssessInfo) {
  245. return json_fail('该评论不存在!');
  246. }
  247. $oldDoodsAssessInfo = $goodsAssessInfo;
  248. $result = $goodsAssessInfo->delete();
  249. if (!$result) {
  250. return json_fail('删除失败');
  251. } else {
  252. $logSubject = '删除一个类原味分类,名字:' . $goodsAssessInfo->name;
  253. $logSvalue = $oldDoodsAssessInfo->manager_id;
  254. $logDbData = [
  255. 'after_items' => [
  256. ],
  257. 'before_items' => [
  258. $oldDoodsAssessInfo->toArray(),
  259. ],
  260. ];
  261. $this->log($logSubject, $logSvalue, $logDbData);
  262. return new PaymentSuccessUidResponse($inputData['uid']);
  263. }
  264. }
  265. /**
  266. * 订单列表
  267. *
  268. * @param ValidatorFactoryInterface $validatorFactory
  269. * @return mixed|OriginaOrderListsResponse
  270. */
  271. public function orderLists(ValidatorFactoryInterface $validatorFactory)
  272. {
  273. $inputData = $this->getJsonData();
  274. $rules = [
  275. 'page' => 'nullable|integer',
  276. 'page_size' => 'nullable|integer',
  277. 'buy_uid' => 'nullable|string',
  278. 'sell_uid' => 'nullable|string',
  279. 'order_sn' => 'nullable|string',
  280. 'order_status' => 'nullable|in:1,2,3,4,5',
  281. 'pay_status' => 'nullable|in:1,2,3',
  282. 'redund_status' => 'nullable|in:1,2,3,4',
  283. 'goods_name' => 'nullable|string',
  284. ];
  285. $validator = $validatorFactory->make($inputData, $rules);
  286. if ($validator->fails()) {
  287. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  288. return json_fail($validator->errors()->first());
  289. }
  290. $orders = [
  291. ['created_at', 'DESC'],
  292. ];
  293. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  294. if ($pageSize > 500) {
  295. $pageSize = CommonConstant::PAGE_SIZE;
  296. }
  297. $page = format_page($inputData['page'] ?? 1);
  298. $res = make(OriginalOrderRepository::class)->pushCriteria(new OriginalOrderCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  299. return new OriginaOrderListsResponse($res);
  300. }
  301. /**
  302. * 操作订单
  303. *
  304. * @param ValidatorFactoryInterface $validatorFactory
  305. * @return mixed|PaymentSuccessUidResponse
  306. */
  307. public function orderUpdate(ValidatorFactoryInterface $validatorFactory)
  308. {
  309. $inputData = $this->getJsonData();
  310. $rules = [
  311. 'uid' => 'required|string',
  312. 'order_status' => 'nullable|in:3,4,5',
  313. 'redund_status' => 'nullable|in:3,4',
  314. 'denial_reason' => 'nullable|string|max:255',
  315. 'courier_number' => 'nullable|string',
  316. 'courier_firm' => 'nullable|string',
  317. 'logistics_info' => 'nullable|string',
  318. ];
  319. $validator = $validatorFactory->make($inputData, $rules);
  320. if ($validator->fails()) {
  321. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  322. return json_fail($validator->errors()->first());
  323. }
  324. $OriginalOrderRep = make(OriginalOrderRepository::class);
  325. $orderInfo = $OriginalOrderRep->findBy('uid', $inputData['uid']);
  326. if (!$orderInfo) {
  327. return json_fail('该订单不存在!');
  328. }
  329. $oldOrderInfo = clone $orderInfo;
  330. $msg = '订单状态改变, 订单号' . $oldOrderInfo->order_sn;
  331. if (!empty($inputData['order_status'])) {
  332. switch ($inputData['order_status']) {
  333. case 3:
  334. $msg = '待发货订单发货,订单号:' . $oldOrderInfo->order_sn;
  335. break;
  336. case 4:
  337. $data = [
  338. 'goods_uid' => $orderInfo->goods_uid,
  339. 'buy_uid' => $orderInfo->buy_uid,
  340. 'goods_name' => $orderInfo->goods_name,
  341. 'order_sn' => $orderInfo->order_sn,
  342. 'comment_fraction' => 3,
  343. 'comment' => '商品很棒!'
  344. ];
  345. // 确认收货
  346. $res = $OriginalOrderRep->confirmReceipt($data);
  347. if (!$res) {
  348. return json_fail('确认收货失败');
  349. }
  350. $msg = '待收货订单确认收货,订单号:' . $oldOrderInfo->order_sn;
  351. break;
  352. }
  353. $orderInfo->order_status = $inputData['order_status'];
  354. }
  355. if (!empty($inputData['redund_status'])) {
  356. switch ($inputData['redund_status']) {
  357. case 3:
  358. $msg = '订单退款驳回,订单号:' . $oldOrderInfo->order_sn;
  359. $oldOrderInfo->order_status = 1;
  360. break;
  361. case 4:
  362. // 退款
  363. $res = $OriginalOrderRep->refund($oldOrderInfo->toArray());
  364. if (!$res) {
  365. return json_fail('退款失败');
  366. }
  367. $msg = '订单退款确认成功,订单号:' . $oldOrderInfo->order_sn;
  368. break;
  369. }
  370. $orderInfo->refund_end_time = date('Y-m-d H:i:s');
  371. $orderInfo->redund_status = $inputData['redund_status'];
  372. }
  373. if (!empty($inputData['denial_reason'])) {
  374. $orderInfo->denial_reason = $inputData['denial_reason'];
  375. }
  376. if (!empty($inputData['courier_number'])) {
  377. $orderInfo->courier_number = $inputData['courier_number'];
  378. }
  379. if (!empty($inputData['courier_firm'])) {
  380. $orderInfo->courier_firm = $inputData['courier_firm'];
  381. }
  382. if (!empty($inputData['logistics_info'])) {
  383. $orderInfo->logistics_info = $inputData['logistics_info'];
  384. }
  385. $result = $orderInfo->save();
  386. if (!$result) {
  387. return json_fail('操作成功');
  388. } else {
  389. $logSubject = $msg;
  390. $logSvalue = $oldOrderInfo->manager_id;
  391. $logDbData = [
  392. 'after_items' => [
  393. $orderInfo->toArray()
  394. ],
  395. 'before_items' => [
  396. $oldOrderInfo->toArray(),
  397. ],
  398. ];
  399. $this->log($logSubject, $logSvalue, $logDbData);
  400. return new PaymentSuccessUidResponse($inputData['uid']);
  401. }
  402. }
  403. /**
  404. * 店铺列表
  405. *
  406. * @param ValidatorFactoryInterface $validatorFactory
  407. * @return mixed
  408. */
  409. public function shopsList(ValidatorFactoryInterface $validatorFactory)
  410. {
  411. $inputData = $this->getJsonData();
  412. $rules = [
  413. 'title' => 'nullable|string',
  414. 'is_certified' => 'nullable|in:1,2',
  415. ];
  416. $validator = $validatorFactory->make($inputData, $rules);
  417. if ($validator->fails()) {
  418. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  419. return json_fail($validator->errors()->first());
  420. }
  421. $orders = [
  422. ['created_at', 'DESC'],
  423. ];
  424. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  425. if ($pageSize > 500) {
  426. $pageSize = CommonConstant::PAGE_SIZE;
  427. }
  428. $page = format_page($inputData['page'] ?? 1);
  429. $res = make(ShopsRepository::class)->pushCriteria(new ShopsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  430. foreach ($res->items() as &$val) {
  431. $val->province = substr($val->province,0,strlen($val->province) - 6);
  432. $val->city = substr($val->city,0,strlen($val->city) - 6);
  433. $val->region = substr($val->region,0,strlen($val->region) - 6);
  434. $val->user_nick = $val->user->nick;
  435. $val->cover64 = '';
  436. unset($val->user);
  437. }
  438. return json_success($res);
  439. }
  440. /**
  441. * 添加店铺
  442. *
  443. * @param ValidatorFactoryInterface $validatorFactory
  444. * @return mixed|PaymentSuccessUidResponse
  445. */
  446. public function shopsAdd(ValidatorFactoryInterface $validatorFactory)
  447. {
  448. $inputData = $this->getJsonData();
  449. $rules = [
  450. 'user_uid' => 'required|string',
  451. 'title' => 'required|string',
  452. 'share_ratio' => 'required|integer',
  453. 'credit_value' => 'required|integer',
  454. 'sort' => 'required|integer',
  455. 'steer_level' => 'required|integer',
  456. 'is_certified' => 'required|in:1,2',
  457. 'cover' => 'required|string',
  458. 'delivery_address' => 'required',
  459. 'introduce' => 'required|string',
  460. 'tg' => 'nullable|string',
  461. 'qq' => 'nullable|string',
  462. 'margin' => 'required',
  463. ];
  464. $validator = $validatorFactory->make($inputData, $rules);
  465. if ($validator->fails()) {
  466. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  467. return json_fail($validator->errors()->first());
  468. }
  469. $userId = make(UserRepository::class)->findBy('code', $inputData['user_uid'], ['id']);
  470. if (empty($userId)) {
  471. return json_fail('绑定的用户不存在');
  472. }
  473. $setArr = [
  474. 'uid' => $inputData['user_uid'],
  475. 'title' => $inputData['title'],
  476. 'credit_value' => $inputData['credit_value'],
  477. 'sort' => $inputData['sort'],
  478. 'steer_level' => $inputData['steer_level'],
  479. 'is_certified' => $inputData['is_certified'],
  480. 'province' => $inputData['delivery_address'][0] . '000000',
  481. 'city' => $inputData['delivery_address'][1] . '000000',
  482. 'region' => $inputData['delivery_address'][2] . '000000',
  483. 'cover' => $inputData['cover'],
  484. 'margin' => $inputData['margin'],
  485. 'goods_count' => $inputData['goods_count'] ?: 0,
  486. 'goods_up_count' => $inputData['goods_up_count'] ?: 0,
  487. 'frozen_amount' => $inputData['frozen_amount'] ?: 0,
  488. 'amount' => $inputData['amount'] ?: 0,
  489. 'introduce' => $inputData['introduce'],
  490. 'share_ratio' => $inputData['share_ratio'],
  491. 'tg' => $inputData['tg'],
  492. 'qq' => $inputData['qq'],
  493. ];
  494. $result = make(ShopsRepository::class)->create($setArr);
  495. if (!$result) {
  496. return json_fail('添加失败');
  497. } else {
  498. $logSubject = '添加一个店铺:' . $inputData['title'];
  499. $logSvalue = $result->uid;
  500. $logDbData = [
  501. 'after_items' => [
  502. $result->toArray(),
  503. ],
  504. 'before_items' => [],
  505. ];
  506. $this->log($logSubject, $logSvalue, $logDbData);
  507. return new PaymentSuccessUidResponse($result->uid);
  508. }
  509. }
  510. /**
  511. * 店铺修改
  512. *
  513. * @param ValidatorFactoryInterface $validatorFactory
  514. * @return mixed|PaymentSuccessUidResponse
  515. */
  516. public function shopsEdit(ValidatorFactoryInterface $validatorFactory)
  517. {
  518. $inputData = $this->getJsonData();
  519. $rules = [
  520. 'user_uid' => 'required|string',
  521. 'title' => 'nullable|string',
  522. 'share_ratio' => 'nullable|integer',
  523. 'credit_value' => 'nullable|integer',
  524. 'sort' => 'nullable|integer',
  525. 'steer_level' => 'nullable|integer',
  526. 'is_certified' => 'nullable|in:1,2',
  527. 'cover' => 'nullable|string',
  528. 'delivery_address' => 'required',
  529. 'goods_count' => 'nullable|integer',
  530. 'goods_up_count' => 'nullable|integer',
  531. 'introduce' => 'nullable|string',
  532. 'tg' => 'nullable|string',
  533. 'qq' => 'nullable|string',
  534. 'margin' => 'required',
  535. 'frozen_amount' => 'required',
  536. 'amount' => 'required',
  537. ];
  538. $validator = $validatorFactory->make($inputData, $rules);
  539. if ($validator->fails()) {
  540. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  541. return json_fail($validator->errors()->first());
  542. }
  543. $shopsInfo = make(ShopsRepository::class)->findBy('uid', $inputData['user_uid']);
  544. if (empty($shopsInfo)) {
  545. return json_fail('店铺不存在');
  546. }
  547. $oldShopsInfo = clone $shopsInfo;
  548. if (!empty($inputData['title'])) {
  549. $shopsInfo->title = $inputData['title'];
  550. }
  551. if (!empty($inputData['credit_value'])) {
  552. $shopsInfo->credit_value = $inputData['credit_value'];
  553. }
  554. if (!empty($inputData['stor'])) {
  555. $shopsInfo->stor = $inputData['stor'];
  556. }
  557. if (!empty($inputData['steer_level'])) {
  558. $shopsInfo->steer_level = $inputData['steer_level'];
  559. }
  560. if (!empty($inputData['is_certified'])) {
  561. $shopsInfo->is_certified = $inputData['is_certified'];
  562. }
  563. if (!empty($inputData['cover'])) {
  564. $shopsInfo->cover = $inputData['cover'];
  565. }
  566. if (!empty($inputData['is_certified'])) {
  567. $shopsInfo->is_certified = $inputData['is_certified'];
  568. }
  569. if (!empty($inputData['delivery_address'])) {
  570. $shopsInfo->province = $inputData['delivery_address'][0] . '000000';
  571. $shopsInfo->city = $inputData['delivery_address'][1] . '000000';
  572. $shopsInfo->region = $inputData['delivery_address'][2] . '000000';
  573. }
  574. if (!empty($inputData['share_ratio'])) {
  575. $shopsInfo->share_ratio = $inputData['share_ratio'];
  576. }
  577. if (!empty($inputData['goods_count'])) {
  578. $shopsInfo->goods_count = $inputData['goods_count'];
  579. }
  580. if (!empty($inputData['goods_up_count'])) {
  581. $shopsInfo->goods_up_count = $inputData['goods_up_count'];
  582. }
  583. if (!empty($inputData['introduce'])) {
  584. $shopsInfo->introduce = $inputData['introduce'];
  585. }
  586. if (!empty($inputData['tg'])) {
  587. $shopsInfo->tg = $inputData['tg'];
  588. }
  589. if (!empty($inputData['qq'])) {
  590. $shopsInfo->qq = $inputData['qq'];
  591. }
  592. if (!empty($inputData['margin'])) {
  593. $shopsInfo->margin = $inputData['margin'];
  594. }
  595. $result = $shopsInfo->save();
  596. if (!$result) {
  597. return json_fail('操作失败');
  598. } else {
  599. $logSubject = $inputData['title'];
  600. $logSvalue = $oldShopsInfo->uid;
  601. $logDbData = [
  602. 'after_items' => [
  603. $shopsInfo->toArray()
  604. ],
  605. 'before_items' => [
  606. $oldShopsInfo->toArray(),
  607. ],
  608. ];
  609. $this->log($logSubject, $logSvalue, $logDbData);
  610. return new PaymentSuccessUidResponse($inputData['uid']);
  611. }
  612. }
  613. /**
  614. * 商品列表
  615. *
  616. * @param ValidatorFactoryInterface $validatorFactory
  617. * @return mixed|OriginaGoodsListsResponse
  618. */
  619. public function goodsList(ValidatorFactoryInterface $validatorFactory)
  620. {
  621. $inputData = $this->getJsonData();
  622. $rules = [
  623. 'title' => 'nullable|string',
  624. 'sell_uid' => 'nullable|string',
  625. 'status' => 'nullable|in:1,2,3,4'
  626. ];
  627. $validator = $validatorFactory->make($inputData, $rules);
  628. if ($validator->fails()) {
  629. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  630. return json_fail($validator->errors()->first());
  631. }
  632. $orders = [
  633. ['created_at', 'DESC'],
  634. ];
  635. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  636. if ($pageSize > 500) {
  637. $pageSize = CommonConstant::PAGE_SIZE;
  638. }
  639. $page = format_page($inputData['page'] ?? 1);
  640. $res = make(OriginalRepository::class)->pushCriteria(new GoodsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  641. return new OriginaGoodsListsResponse($res);
  642. }
  643. /**
  644. * 添加商品
  645. *
  646. * @param ValidatorFactoryInterface $validatorFactory
  647. * @return mixed|PaymentSuccessUidResponse\
  648. */
  649. public function goodsAdd(ValidatorFactoryInterface $validatorFactory)
  650. {
  651. $inputData = $this->getJsonData();
  652. $rules = [
  653. 'title' => 'required|string',
  654. 'class_uid' => 'required|string',
  655. 'shops_uid' => 'required|string',
  656. 'sort' => 'required|integer',
  657. 'steer_level' => 'required|integer',
  658. 'cover' => 'required|string',
  659. 'status' => 'required|in:1,2,3,4',
  660. 'coins' => 'required|integer',
  661. 'original_cions' => 'required|integer',
  662. 'member_coins' => 'required|integer',
  663. 'stock' => 'required|integer',
  664. 'likes' => 'required|integer',
  665. 'browse' => 'required|integer',
  666. 'number_orders' => 'required|integer',
  667. 'appraise' => 'required|integer',
  668. 'introduce' => 'required|string',
  669. 'photo_address' => 'required',
  670. ];
  671. $validator = $validatorFactory->make($inputData, $rules);
  672. if ($validator->fails()) {
  673. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  674. return json_fail($validator->errors()->first());
  675. }
  676. $result = make(OriginalRepository::class)->createOne($inputData);
  677. if (!$result) {
  678. return json_fail('添加失败');
  679. } else {
  680. $logSubject = '添加一个商品:' . $inputData['title'];
  681. $logSvalue = $result->uid;
  682. $logDbData = [
  683. 'after_items' => [
  684. $result->toArray(),
  685. ],
  686. 'before_items' => [],
  687. ];
  688. $this->log($logSubject, $logSvalue, $logDbData);
  689. return new PaymentSuccessUidResponse($result->uid);
  690. }
  691. }
  692. public function goodsEdit(ValidatorFactoryInterface $validatorFactory)
  693. {
  694. $inputData = $this->getJsonData();
  695. $rules = [
  696. 'uid' => 'required|string',
  697. 'title' => 'nullable|string',
  698. 'class_uid' => 'required|string',
  699. 'shops_uid' => 'required|string',
  700. 'sort' => 'nullable|integer',
  701. 'steer_level' => 'nullable|integer',
  702. 'cover' => 'nullable|string',
  703. 'status' => 'nullable|in:1,2,3,4',
  704. 'coins' => 'nullable|integer',
  705. 'original_cions' => 'nullable|integer',
  706. 'member_coins' => 'nullable|integer',
  707. 'stock' => 'nullable|integer',
  708. 'likes' => 'nullable|integer',
  709. 'browse' => 'nullable|integer',
  710. 'number_orders' => 'nullable|integer',
  711. 'appraise' => 'nullable|integer',
  712. 'introduce' => 'nullable|string',
  713. ];
  714. $validator = $validatorFactory->make($inputData, $rules);
  715. if ($validator->fails()) {
  716. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  717. return json_fail($validator->errors()->first());
  718. }
  719. $oldGoodsInfo = [];
  720. $goodsInfo = make(OriginalRepository::class)->updateOne($inputData, $oldGoodsInfo);
  721. if (!$goodsInfo) {
  722. return json_fail('修改失败失败');
  723. } else {
  724. $logSubject = '修改一个商品:' . $inputData['title'];
  725. $logSvalue = $oldGoodsInfo['uid'];
  726. $logDbData = [
  727. 'after_items' => [
  728. $goodsInfo
  729. ],
  730. 'before_items' => [
  731. $oldGoodsInfo,
  732. ],
  733. ];
  734. $this->log($logSubject, $logSvalue, $logDbData);
  735. return new PaymentSuccessUidResponse($goodsInfo->uid);
  736. }
  737. }
  738. /**
  739. * 删除商品
  740. *
  741. * @param ValidatorFactoryInterface $validatorFactory
  742. * @return mixed|PaymentSuccessUidResponse
  743. */
  744. public function shopsDelete(ValidatorFactoryInterface $validatorFactory)
  745. {
  746. $inputData = $this->getJsonData();
  747. $rules = [
  748. 'uid' => 'required|string',
  749. ];
  750. $validator = $validatorFactory->make($inputData, $rules);
  751. if ($validator->fails()) {
  752. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  753. return json_fail($validator->errors()->first());
  754. }
  755. $goodsInfo = make(OriginalRepository::class)->findBy('uid', $inputData['uid']);
  756. if (empty($goodsInfo)) {
  757. return json_fail('商品不存在');
  758. }
  759. $oldGoodsInfo = clone $goodsInfo;
  760. $result = $goodsInfo->delete();
  761. if (!$result) {
  762. return json_fail('删除失败');
  763. } else {
  764. $logSubject = '删除一个类原味分类,名字:' . $goodsInfo->title;
  765. $logSvalue = $oldGoodsInfo->uid;
  766. $logDbData = [
  767. 'after_items' => [
  768. ],
  769. 'before_items' => [
  770. $oldGoodsInfo->toArray(),
  771. ],
  772. ];
  773. $this->log($logSubject, $logSvalue, $logDbData);
  774. return new PaymentSuccessUidResponse($inputData['uid']);
  775. }
  776. }
  777. /**
  778. * 收货地址
  779. *
  780. * @param ValidatorFactoryInterface $validatorFactory
  781. * @return mixed
  782. */
  783. public function userAddress(ValidatorFactoryInterface $validatorFactory)
  784. {
  785. $inputData = $this->getJsonData();
  786. $rules = [
  787. 'user_uid' => 'nullable|string',
  788. 'name' => 'nullable|string',
  789. ];
  790. $validator = $validatorFactory->make($inputData, $rules);
  791. if ($validator->fails()) {
  792. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  793. return json_fail($validator->errors()->first());
  794. }
  795. $orders = [
  796. ['created_at', 'DESC'],
  797. ];
  798. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  799. if ($pageSize > 500) {
  800. $pageSize = CommonConstant::PAGE_SIZE;
  801. }
  802. $page = format_page($inputData['page'] ?? 1);
  803. $res = make(UserShippingAddressRepository::class)->pushCriteria(new UserShippingAddressCriterias($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  804. foreach ($res->items() as &$value) {
  805. $value->user_nick = $value->user->nick;
  806. unset($value->user);
  807. }
  808. return json_success($res);
  809. }
  810. /**
  811. * 商品所需下拉
  812. *
  813. * @return mixed
  814. */
  815. public function getDown()
  816. {
  817. $res['category'] = make(OriginalCategoryRepository::class)->findAllBy('type', 1, ['uid', 'name'])->keyBy('uid');
  818. $res['shops'] = make(ShopsRepository::class)->findAllBy('is_certified', 2, ['uid', 'title'])->keyBy('uid');
  819. return json_success($res);
  820. }
  821. }