Modules_Manage_Controllers_OriginaController.proxy.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. use \Hyperf\Di\Aop\ProxyTrait;
  28. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  29. function __construct()
  30. {
  31. if (method_exists(parent::class, '__construct')) {
  32. parent::__construct(...func_get_args());
  33. }
  34. $this->__handlePropertyHandler(__CLASS__);
  35. }
  36. /**
  37. * 分类列表
  38. *
  39. * @param ValidatorFactoryInterface $validatorFactory
  40. * @return mixed|CommonPagesResponse
  41. */
  42. public function categoryLists(ValidatorFactoryInterface $validatorFactory)
  43. {
  44. $inputData = $this->getJsonData();
  45. $rules = ['page' => 'nullable|integer', 'page_size' => 'nullable|integer', 'sttaus' => 'nullable|string', 'name' => 'nullable|string'];
  46. $validator = $validatorFactory->make($inputData, $rules);
  47. if ($validator->fails()) {
  48. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  49. return json_fail($validator->errors()->first());
  50. }
  51. $orders = [['created_at', 'DESC']];
  52. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  53. if ($pageSize > 500) {
  54. $pageSize = CommonConstant::PAGE_SIZE;
  55. }
  56. $page = format_page($inputData['page'] ?? 1);
  57. $res = make(OriginalClassRepository::class)->pushCriteria(new OriginalClassCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  58. return new CommonPagesResponse($res);
  59. }
  60. /**
  61. * 添加分类
  62. *
  63. * @param ValidatorFactoryInterface $validatorFactory
  64. * @return mixed|PaymentSuccessUidResponse
  65. */
  66. public function categoryAdd(ValidatorFactoryInterface $validatorFactory)
  67. {
  68. $inputData = $this->getJsonData();
  69. $rules = ['name' => 'required|string', 'status' => 'required|in:1,2', 'type' => 'required|in:1,2', 'sort' => 'required|integer'];
  70. $validator = $validatorFactory->make($inputData, $rules);
  71. if ($validator->fails()) {
  72. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  73. return json_fail($validator->errors()->first());
  74. }
  75. $setarr = ['name' => $inputData['name'], 'status' => $inputData['status'], 'type' => $inputData['type'], 'sort' => $inputData['sort']];
  76. $result = make(OriginalClassRepository::class)->create($setarr);
  77. if (!$result) {
  78. return json_fail('添加失败');
  79. } else {
  80. $logSubject = '添加一个原味分类,分类名字:' . $inputData['name'];
  81. $logSvalue = $result->uid;
  82. $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
  83. $this->log($logSubject, $logSvalue, $logDbData);
  84. return new PaymentSuccessUidResponse($result->uid);
  85. }
  86. }
  87. /**
  88. * 修改分类
  89. *
  90. * @param ValidatorFactoryInterface $validatorFactory
  91. * @return mixed|PaymentSuccessUidResponse
  92. */
  93. public function categoryEdit(ValidatorFactoryInterface $validatorFactory)
  94. {
  95. $inputData = $this->getJsonData();
  96. $rules = ['name' => 'nullable|string', 'status' => 'nullable|in:1,2', 'type' => 'nullable|in:1,2', 'sort' => 'nullable|integer', 'uid' => 'required|string'];
  97. $validator = $validatorFactory->make($inputData, $rules);
  98. if ($validator->fails()) {
  99. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  100. return json_fail($validator->errors()->first());
  101. }
  102. $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
  103. if (!$categoryInfo) {
  104. return json_fail('该类型不存在!');
  105. }
  106. $oldCategoryInfo = clone $categoryInfo;
  107. if (!empty($inputData['name'])) {
  108. $categoryInfo->name = $inputData['name'];
  109. }
  110. if (!empty($inputData['status'])) {
  111. $categoryInfo->status = $inputData['status'];
  112. }
  113. if (!empty($inputData['type'])) {
  114. $categoryInfo->type = $inputData['type'];
  115. }
  116. if (!empty($inputData['sort'])) {
  117. $categoryInfo->sort = $inputData['sort'];
  118. }
  119. $result = $categoryInfo->save();
  120. if (!$result) {
  121. return json_fail('修改失败');
  122. } else {
  123. $logSubject = '修改一个原味分类,名字:' . $oldCategoryInfo->name;
  124. $logSvalue = $oldCategoryInfo->uid;
  125. $logDbData = ['after_items' => [$categoryInfo->toArray()], 'before_items' => [$oldCategoryInfo->toArray()]];
  126. $this->log($logSubject, $logSvalue, $logDbData);
  127. return new PaymentSuccessUidResponse($categoryInfo->uid);
  128. }
  129. }
  130. /**
  131. * 删除分类
  132. *
  133. * @param ValidatorFactoryInterface $validatorFactory
  134. * @return mixed|PaymentSuccessUidResponse
  135. */
  136. public function categoryDelete(ValidatorFactoryInterface $validatorFactory)
  137. {
  138. $inputData = $this->getJsonData();
  139. $rules = ['uid' => 'required|string'];
  140. $validator = $validatorFactory->make($inputData, $rules);
  141. if ($validator->fails()) {
  142. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  143. return json_fail($validator->errors()->first());
  144. }
  145. $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
  146. if (!$categoryInfo) {
  147. return json_fail('该类型不存在!');
  148. }
  149. $oldCategoryInfo = clone $categoryInfo;
  150. $result = $categoryInfo->delete();
  151. if (!$result) {
  152. return json_fail('删除失败');
  153. } else {
  154. $logSubject = '删除一个类原味分类,名字:' . $oldCategoryInfo->name;
  155. $logSvalue = $oldCategoryInfo->manager_id;
  156. $logDbData = ['after_items' => [], 'before_items' => [$oldCategoryInfo->toArray()]];
  157. $this->log($logSubject, $logSvalue, $logDbData);
  158. return new PaymentSuccessUidResponse($inputData['uid']);
  159. }
  160. }
  161. /**
  162. * 评价列表
  163. *
  164. * @param ValidatorFactoryInterface $validatorFactory
  165. * @return mixed|void
  166. */
  167. public function assessLists(ValidatorFactoryInterface $validatorFactory)
  168. {
  169. $inputData = $this->getJsonData();
  170. $rules = ['page' => 'nullable|integer', 'page_size' => 'nullable|integer', 'buy_uid' => 'nullable|string', 'goods_name' => 'nullable|string'];
  171. $validator = $validatorFactory->make($inputData, $rules);
  172. if ($validator->fails()) {
  173. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  174. return json_fail($validator->errors()->first());
  175. }
  176. $orders = [['created_at', 'DESC']];
  177. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  178. if ($pageSize > 500) {
  179. $pageSize = CommonConstant::PAGE_SIZE;
  180. }
  181. $page = format_page($inputData['page'] ?? 1);
  182. $res = make(GoodsAssessRepository::class)->pushCriteria(new GoodsAssessCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  183. return new OriginaAssessListsResponse($res);
  184. }
  185. /**
  186. * 删除评论
  187. *
  188. * @param ValidatorFactoryInterface $validatorFactory
  189. * @return mixed|PaymentSuccessUidResponse
  190. */
  191. public function assessDelete(ValidatorFactoryInterface $validatorFactory)
  192. {
  193. $inputData = $this->getJsonData();
  194. $rules = ['uid' => 'nullable|string'];
  195. $validator = $validatorFactory->make($inputData, $rules);
  196. if ($validator->fails()) {
  197. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  198. return json_fail($validator->errors()->first());
  199. }
  200. $goodsAssessInfo = make(GoodsAssessRepository::class)->findBy('uid', $inputData['uid']);
  201. if (!$goodsAssessInfo) {
  202. return json_fail('该评论不存在!');
  203. }
  204. $oldDoodsAssessInfo = $goodsAssessInfo;
  205. $result = $goodsAssessInfo->delete();
  206. if (!$result) {
  207. return json_fail('删除失败');
  208. } else {
  209. $logSubject = '删除一个类原味分类,名字:' . $goodsAssessInfo->name;
  210. $logSvalue = $oldDoodsAssessInfo->manager_id;
  211. $logDbData = ['after_items' => [], 'before_items' => [$oldDoodsAssessInfo->toArray()]];
  212. $this->log($logSubject, $logSvalue, $logDbData);
  213. return new PaymentSuccessUidResponse($inputData['uid']);
  214. }
  215. }
  216. /**
  217. * 订单列表
  218. *
  219. * @param ValidatorFactoryInterface $validatorFactory
  220. * @return mixed|OriginaOrderListsResponse
  221. */
  222. public function orderLists(ValidatorFactoryInterface $validatorFactory)
  223. {
  224. $inputData = $this->getJsonData();
  225. $rules = ['page' => 'nullable|integer', 'page_size' => 'nullable|integer', 'buy_uid' => 'nullable|string', 'sell_uid' => 'nullable|string', 'order_sn' => 'nullable|string', 'order_status' => 'nullable|in:1,2,3,4,5', 'pay_status' => 'nullable|in:1,2,3', 'redund_status' => 'nullable|in:1,2,3,4', 'goods_name' => 'nullable|string'];
  226. $validator = $validatorFactory->make($inputData, $rules);
  227. if ($validator->fails()) {
  228. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  229. return json_fail($validator->errors()->first());
  230. }
  231. $orders = [['created_at', 'DESC']];
  232. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  233. if ($pageSize > 500) {
  234. $pageSize = CommonConstant::PAGE_SIZE;
  235. }
  236. $page = format_page($inputData['page'] ?? 1);
  237. $res = make(OriginalOrderRepository::class)->pushCriteria(new OriginalOrderCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  238. return new OriginaOrderListsResponse($res);
  239. }
  240. /**
  241. * 操作订单
  242. *
  243. * @param ValidatorFactoryInterface $validatorFactory
  244. * @return mixed|PaymentSuccessUidResponse
  245. */
  246. public function orderUpdate(ValidatorFactoryInterface $validatorFactory)
  247. {
  248. $inputData = $this->getJsonData();
  249. $rules = ['uid' => 'required|string', 'order_status' => 'nullable|in:3,4,5', 'redund_status' => 'nullable|in:3,4', 'denial_reason' => 'nullable|string|max:255', 'courier_number' => 'nullable|string', 'courier_firm' => 'nullable|string', 'logistics_info' => 'nullable|string'];
  250. $validator = $validatorFactory->make($inputData, $rules);
  251. if ($validator->fails()) {
  252. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  253. return json_fail($validator->errors()->first());
  254. }
  255. $OriginalOrderRep = make(OriginalOrderRepository::class);
  256. $orderInfo = $OriginalOrderRep->findBy('uid', $inputData['uid']);
  257. if (!$orderInfo) {
  258. return json_fail('该订单不存在!');
  259. }
  260. $oldOrderInfo = clone $orderInfo;
  261. $msg = '订单状态改变, 订单号' . $oldOrderInfo->order_sn;
  262. if (!empty($inputData['order_status'])) {
  263. switch ($inputData['order_status']) {
  264. case 3:
  265. $msg = '待发货订单发货,订单号:' . $oldOrderInfo->order_sn;
  266. break;
  267. case 4:
  268. $data = ['goods_uid' => $orderInfo->goods_uid, 'buy_uid' => $orderInfo->buy_uid, 'goods_name' => $orderInfo->goods_name, 'order_sn' => $orderInfo->order_sn, 'comment_fraction' => 3, 'comment' => '商品很棒!'];
  269. // 确认收货
  270. $res = $OriginalOrderRep->confirmReceipt($data);
  271. if (!$res) {
  272. return json_fail('确认收货失败');
  273. }
  274. $msg = '待收货订单确认收货,订单号:' . $oldOrderInfo->order_sn;
  275. break;
  276. }
  277. $orderInfo->order_status = $inputData['order_status'];
  278. }
  279. if (!empty($inputData['redund_status'])) {
  280. switch ($inputData['redund_status']) {
  281. case 3:
  282. $msg = '订单退款驳回,订单号:' . $oldOrderInfo->order_sn;
  283. $oldOrderInfo->order_status = 1;
  284. break;
  285. case 4:
  286. // 退款
  287. $res = $OriginalOrderRep->refund($oldOrderInfo->toArray());
  288. if (!$res) {
  289. return json_fail('退款失败');
  290. }
  291. $msg = '订单退款确认成功,订单号:' . $oldOrderInfo->order_sn;
  292. break;
  293. }
  294. $orderInfo->refund_end_time = date('Y-m-d H:i:s');
  295. $orderInfo->redund_status = $inputData['redund_status'];
  296. }
  297. if (!empty($inputData['denial_reason'])) {
  298. $orderInfo->denial_reason = $inputData['denial_reason'];
  299. }
  300. if (!empty($inputData['courier_number'])) {
  301. $orderInfo->courier_number = $inputData['courier_number'];
  302. }
  303. if (!empty($inputData['courier_firm'])) {
  304. $orderInfo->courier_firm = $inputData['courier_firm'];
  305. }
  306. if (!empty($inputData['logistics_info'])) {
  307. $orderInfo->logistics_info = $inputData['logistics_info'];
  308. }
  309. $result = $orderInfo->save();
  310. if (!$result) {
  311. return json_fail('操作成功');
  312. } else {
  313. $logSubject = $msg;
  314. $logSvalue = $oldOrderInfo->manager_id;
  315. $logDbData = ['after_items' => [$orderInfo->toArray()], 'before_items' => [$oldOrderInfo->toArray()]];
  316. $this->log($logSubject, $logSvalue, $logDbData);
  317. return new PaymentSuccessUidResponse($inputData['uid']);
  318. }
  319. }
  320. /**
  321. * 店铺列表
  322. *
  323. * @param ValidatorFactoryInterface $validatorFactory
  324. * @return mixed
  325. */
  326. public function shopsList(ValidatorFactoryInterface $validatorFactory)
  327. {
  328. $inputData = $this->getJsonData();
  329. $rules = ['title' => 'nullable|string', 'is_certified' => 'nullable|in:1,2'];
  330. $validator = $validatorFactory->make($inputData, $rules);
  331. if ($validator->fails()) {
  332. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  333. return json_fail($validator->errors()->first());
  334. }
  335. $orders = [['created_at', 'DESC']];
  336. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  337. if ($pageSize > 500) {
  338. $pageSize = CommonConstant::PAGE_SIZE;
  339. }
  340. $page = format_page($inputData['page'] ?? 1);
  341. $res = make(ShopsRepository::class)->pushCriteria(new ShopsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  342. foreach ($res->items() as &$val) {
  343. $val->province = substr($val->province, 0, strlen($val->province) - 6);
  344. $val->city = substr($val->city, 0, strlen($val->city) - 6);
  345. $val->region = substr($val->region, 0, strlen($val->region) - 6);
  346. $val->user_nick = $val->user->nick;
  347. $val->cover64 = '';
  348. unset($val->user);
  349. }
  350. return json_success($res);
  351. }
  352. /**
  353. * 添加店铺
  354. *
  355. * @param ValidatorFactoryInterface $validatorFactory
  356. * @return mixed|PaymentSuccessUidResponse
  357. */
  358. public function shopsAdd(ValidatorFactoryInterface $validatorFactory)
  359. {
  360. $inputData = $this->getJsonData();
  361. $rules = ['user_uid' => 'required|string', 'title' => 'required|string', 'share_ratio' => 'required|integer', 'credit_value' => 'required|integer', 'sort' => 'required|integer', 'steer_level' => 'required|integer', 'is_certified' => 'required|in:1,2', 'cover' => 'required|string', 'delivery_address' => 'required', 'introduce' => 'required|string', 'tg' => 'nullable|string', 'qq' => 'nullable|string', 'margin' => 'required'];
  362. $validator = $validatorFactory->make($inputData, $rules);
  363. if ($validator->fails()) {
  364. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  365. return json_fail($validator->errors()->first());
  366. }
  367. $userId = make(UserRepository::class)->findBy('code', $inputData['user_uid'], ['id']);
  368. if (empty($userId)) {
  369. return json_fail('绑定的用户不存在');
  370. }
  371. $setArr = ['uid' => $inputData['user_uid'], 'title' => $inputData['title'], 'credit_value' => $inputData['credit_value'], 'sort' => $inputData['sort'], 'steer_level' => $inputData['steer_level'], 'is_certified' => $inputData['is_certified'], 'province' => $inputData['delivery_address'][0] . '000000', 'city' => $inputData['delivery_address'][1] . '000000', 'region' => $inputData['delivery_address'][2] . '000000', 'cover' => $inputData['cover'], 'margin' => $inputData['margin'], 'goods_count' => $inputData['goods_count'] ?: 0, 'goods_up_count' => $inputData['goods_up_count'] ?: 0, 'frozen_amount' => $inputData['frozen_amount'] ?: 0, 'amount' => $inputData['amount'] ?: 0, 'introduce' => $inputData['introduce'], 'share_ratio' => $inputData['share_ratio'], 'tg' => $inputData['tg'], 'qq' => $inputData['qq']];
  372. $result = make(ShopsRepository::class)->create($setArr);
  373. if (!$result) {
  374. return json_fail('添加失败');
  375. } else {
  376. $logSubject = '添加一个店铺:' . $inputData['title'];
  377. $logSvalue = $result->uid;
  378. $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
  379. $this->log($logSubject, $logSvalue, $logDbData);
  380. return new PaymentSuccessUidResponse($result->uid);
  381. }
  382. }
  383. /**
  384. * 店铺修改
  385. *
  386. * @param ValidatorFactoryInterface $validatorFactory
  387. * @return mixed|PaymentSuccessUidResponse
  388. */
  389. public function shopsEdit(ValidatorFactoryInterface $validatorFactory)
  390. {
  391. $inputData = $this->getJsonData();
  392. $rules = ['user_uid' => 'required|string', 'title' => 'nullable|string', 'share_ratio' => 'nullable|integer', 'credit_value' => 'nullable|integer', 'sort' => 'nullable|integer', 'steer_level' => 'nullable|integer', 'is_certified' => 'nullable|in:1,2', 'cover' => 'nullable|string', 'delivery_address' => 'required', 'goods_count' => 'nullable|integer', 'goods_up_count' => 'nullable|integer', 'introduce' => 'nullable|string', 'tg' => 'nullable|string', 'qq' => 'nullable|string', 'margin' => 'required', 'frozen_amount' => 'required', 'amount' => 'required'];
  393. $validator = $validatorFactory->make($inputData, $rules);
  394. if ($validator->fails()) {
  395. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  396. return json_fail($validator->errors()->first());
  397. }
  398. $shopsInfo = make(ShopsRepository::class)->findBy('uid', $inputData['user_uid']);
  399. if (empty($shopsInfo)) {
  400. return json_fail('店铺不存在');
  401. }
  402. $oldShopsInfo = clone $shopsInfo;
  403. if (!empty($inputData['title'])) {
  404. $shopsInfo->title = $inputData['title'];
  405. }
  406. if (!empty($inputData['credit_value'])) {
  407. $shopsInfo->credit_value = $inputData['credit_value'];
  408. }
  409. if (!empty($inputData['stor'])) {
  410. $shopsInfo->stor = $inputData['stor'];
  411. }
  412. if (!empty($inputData['steer_level'])) {
  413. $shopsInfo->steer_level = $inputData['steer_level'];
  414. }
  415. if (!empty($inputData['is_certified'])) {
  416. $shopsInfo->is_certified = $inputData['is_certified'];
  417. }
  418. if (!empty($inputData['cover'])) {
  419. $shopsInfo->cover = $inputData['cover'];
  420. }
  421. if (!empty($inputData['is_certified'])) {
  422. $shopsInfo->is_certified = $inputData['is_certified'];
  423. }
  424. if (!empty($inputData['delivery_address'])) {
  425. $shopsInfo->province = $inputData['delivery_address'][0] . '000000';
  426. $shopsInfo->city = $inputData['delivery_address'][1] . '000000';
  427. $shopsInfo->region = $inputData['delivery_address'][2] . '000000';
  428. }
  429. if (!empty($inputData['share_ratio'])) {
  430. $shopsInfo->share_ratio = $inputData['share_ratio'];
  431. }
  432. if (!empty($inputData['goods_count'])) {
  433. $shopsInfo->goods_count = $inputData['goods_count'];
  434. }
  435. if (!empty($inputData['goods_up_count'])) {
  436. $shopsInfo->goods_up_count = $inputData['goods_up_count'];
  437. }
  438. if (!empty($inputData['introduce'])) {
  439. $shopsInfo->introduce = $inputData['introduce'];
  440. }
  441. if (!empty($inputData['tg'])) {
  442. $shopsInfo->tg = $inputData['tg'];
  443. }
  444. if (!empty($inputData['qq'])) {
  445. $shopsInfo->qq = $inputData['qq'];
  446. }
  447. if (!empty($inputData['margin'])) {
  448. $shopsInfo->margin = $inputData['margin'];
  449. }
  450. $result = $shopsInfo->save();
  451. if (!$result) {
  452. return json_fail('操作失败');
  453. } else {
  454. $logSubject = $inputData['title'];
  455. $logSvalue = $oldShopsInfo->uid;
  456. $logDbData = ['after_items' => [$shopsInfo->toArray()], 'before_items' => [$oldShopsInfo->toArray()]];
  457. $this->log($logSubject, $logSvalue, $logDbData);
  458. return new PaymentSuccessUidResponse($inputData['uid']);
  459. }
  460. }
  461. /**
  462. * 商品列表
  463. *
  464. * @param ValidatorFactoryInterface $validatorFactory
  465. * @return mixed|OriginaGoodsListsResponse
  466. */
  467. public function goodsList(ValidatorFactoryInterface $validatorFactory)
  468. {
  469. $inputData = $this->getJsonData();
  470. $rules = ['title' => 'nullable|string', 'sell_uid' => 'nullable|string', 'status' => 'nullable|in:1,2,3,4'];
  471. $validator = $validatorFactory->make($inputData, $rules);
  472. if ($validator->fails()) {
  473. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  474. return json_fail($validator->errors()->first());
  475. }
  476. $orders = [['created_at', 'DESC']];
  477. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  478. if ($pageSize > 500) {
  479. $pageSize = CommonConstant::PAGE_SIZE;
  480. }
  481. $page = format_page($inputData['page'] ?? 1);
  482. $res = make(OriginalRepository::class)->pushCriteria(new GoodsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  483. return new OriginaGoodsListsResponse($res);
  484. }
  485. /**
  486. * 添加商品
  487. *
  488. * @param ValidatorFactoryInterface $validatorFactory
  489. * @return mixed|PaymentSuccessUidResponse\
  490. */
  491. public function goodsAdd(ValidatorFactoryInterface $validatorFactory)
  492. {
  493. $inputData = $this->getJsonData();
  494. $rules = ['title' => 'required|string', 'class_uid' => 'required|string', 'shops_uid' => 'required|string', 'sort' => 'required|integer', 'steer_level' => 'required|integer', 'cover' => 'required|string', 'status' => 'required|in:1,2,3,4', 'coins' => 'required|integer', 'original_cions' => 'required|integer', 'member_coins' => 'required|integer', 'stock' => 'required|integer', 'likes' => 'required|integer', 'browse' => 'required|integer', 'number_orders' => 'required|integer', 'appraise' => 'required|integer', 'introduce' => 'required|string', 'photo_address' => 'required'];
  495. $validator = $validatorFactory->make($inputData, $rules);
  496. if ($validator->fails()) {
  497. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  498. return json_fail($validator->errors()->first());
  499. }
  500. $result = make(OriginalRepository::class)->createOne($inputData);
  501. if (!$result) {
  502. return json_fail('添加失败');
  503. } else {
  504. $logSubject = '添加一个商品:' . $inputData['title'];
  505. $logSvalue = $result->uid;
  506. $logDbData = ['after_items' => [$result->toArray()], 'before_items' => []];
  507. $this->log($logSubject, $logSvalue, $logDbData);
  508. return new PaymentSuccessUidResponse($result->uid);
  509. }
  510. }
  511. public function goodsEdit(ValidatorFactoryInterface $validatorFactory)
  512. {
  513. $inputData = $this->getJsonData();
  514. $rules = ['uid' => 'required|string', 'title' => 'nullable|string', 'class_uid' => 'required|string', 'shops_uid' => 'required|string', 'sort' => 'nullable|integer', 'steer_level' => 'nullable|integer', 'cover' => 'nullable|string', 'status' => 'nullable|in:1,2,3,4', 'coins' => 'nullable|integer', 'original_cions' => 'nullable|integer', 'member_coins' => 'nullable|integer', 'stock' => 'nullable|integer', 'likes' => 'nullable|integer', 'browse' => 'nullable|integer', 'number_orders' => 'nullable|integer', 'appraise' => 'nullable|integer', 'introduce' => 'nullable|string'];
  515. $validator = $validatorFactory->make($inputData, $rules);
  516. if ($validator->fails()) {
  517. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  518. return json_fail($validator->errors()->first());
  519. }
  520. $oldGoodsInfo = [];
  521. $goodsInfo = make(OriginalRepository::class)->updateOne($inputData, $oldGoodsInfo);
  522. if (!$goodsInfo) {
  523. return json_fail('修改失败失败');
  524. } else {
  525. $logSubject = '修改一个商品:' . $inputData['title'];
  526. $logSvalue = $oldGoodsInfo['uid'];
  527. $logDbData = ['after_items' => [$goodsInfo], 'before_items' => [$oldGoodsInfo]];
  528. $this->log($logSubject, $logSvalue, $logDbData);
  529. return new PaymentSuccessUidResponse($goodsInfo->uid);
  530. }
  531. }
  532. /**
  533. * 删除商品
  534. *
  535. * @param ValidatorFactoryInterface $validatorFactory
  536. * @return mixed|PaymentSuccessUidResponse
  537. */
  538. public function shopsDelete(ValidatorFactoryInterface $validatorFactory)
  539. {
  540. $inputData = $this->getJsonData();
  541. $rules = ['uid' => 'required|string'];
  542. $validator = $validatorFactory->make($inputData, $rules);
  543. if ($validator->fails()) {
  544. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  545. return json_fail($validator->errors()->first());
  546. }
  547. $goodsInfo = make(OriginalRepository::class)->findBy('uid', $inputData['uid']);
  548. if (empty($goodsInfo)) {
  549. return json_fail('商品不存在');
  550. }
  551. $oldGoodsInfo = clone $goodsInfo;
  552. $result = $goodsInfo->delete();
  553. if (!$result) {
  554. return json_fail('删除失败');
  555. } else {
  556. $logSubject = '删除一个类原味分类,名字:' . $goodsInfo->title;
  557. $logSvalue = $oldGoodsInfo->uid;
  558. $logDbData = ['after_items' => [], 'before_items' => [$oldGoodsInfo->toArray()]];
  559. $this->log($logSubject, $logSvalue, $logDbData);
  560. return new PaymentSuccessUidResponse($inputData['uid']);
  561. }
  562. }
  563. /**
  564. * 收货地址
  565. *
  566. * @param ValidatorFactoryInterface $validatorFactory
  567. * @return mixed
  568. */
  569. public function userAddress(ValidatorFactoryInterface $validatorFactory)
  570. {
  571. $inputData = $this->getJsonData();
  572. $rules = ['user_uid' => 'nullable|string', 'name' => 'nullable|string'];
  573. $validator = $validatorFactory->make($inputData, $rules);
  574. if ($validator->fails()) {
  575. // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
  576. return json_fail($validator->errors()->first());
  577. }
  578. $orders = [['created_at', 'DESC']];
  579. $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
  580. if ($pageSize > 500) {
  581. $pageSize = CommonConstant::PAGE_SIZE;
  582. }
  583. $page = format_page($inputData['page'] ?? 1);
  584. $res = make(UserShippingAddressRepository::class)->pushCriteria(new UserShippingAddressCriterias($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
  585. foreach ($res->items() as &$value) {
  586. $value->user_nick = $value->user->nick;
  587. unset($value->user);
  588. }
  589. return json_success($res);
  590. }
  591. /**
  592. * 商品所需下拉
  593. *
  594. * @return mixed
  595. */
  596. public function getDown()
  597. {
  598. $res['category'] = make(OriginalCategoryRepository::class)->findAllBy('type', 1, ['uid', 'name'])->keyBy('uid');
  599. $res['shops'] = make(ShopsRepository::class)->findAllBy('is_certified', 2, ['uid', 'title'])->keyBy('uid');
  600. return json_success($res);
  601. }
  602. }