| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- <?php
- namespace Modules\Manage\Controllers;
- use App\Constants\CommonConstant;
- use App\Repositories\Criterias\GoodsAssessCriteria;
- use App\Repositories\Criterias\GoodsCriteria;
- use App\Repositories\Criterias\OrderLimitCriteria;
- use App\Repositories\Criterias\OriginalClassCriteria;
- use App\Repositories\Criterias\OriginalOrderCriteria;
- use App\Repositories\Criterias\ShopsCriteria;
- use App\Repositories\Criterias\UserShippingAddressCriterias;
- use App\Repositories\GoodsAssessRepository;
- use App\Repositories\OriginalCategoryRepository;
- use App\Repositories\OriginalClassRepository;
- use App\Repositories\OriginalOrderRepository;
- use App\Repositories\OriginalRepository;
- use App\Repositories\ShopsRepository;
- use App\Repositories\UserRepository;
- use App\Repositories\UserShippingAddressRepository;
- use Hyperf\Validation\Contract\ValidatorFactoryInterface;
- use Modules\Manage\Responses\CommonPagesResponse;
- use Modules\Manage\Responses\OriginaAssessListsResponse;
- use Modules\Manage\Responses\OriginaGoodsListsResponse;
- use Modules\Manage\Responses\OriginaOrderListsResponse;
- use Modules\Manage\Responses\PaymentSuccessUidResponse;
- class OriginaController extends BaseController
- {
- /**
- * 分类列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|CommonPagesResponse
- */
- public function categoryLists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- 'sttaus' => 'nullable|string',
- 'name' => 'nullable|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(OriginalClassRepository::class)->pushCriteria(new OriginalClassCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new CommonPagesResponse($res);
- }
- /**
- * 添加分类
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function categoryAdd(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'name' => 'required|string',
- 'status' => 'required|in:1,2',
- 'type' => 'required|in:1,2',
- 'sort' => 'required|integer',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $setarr = [
- 'name' => $inputData['name'],
- 'status' => $inputData['status'],
- 'type' => $inputData['type'],
- 'sort' => $inputData['sort'],
- ];
- $result = make(OriginalClassRepository::class)->create($setarr);
- if (!$result) {
- return json_fail('添加失败');
- } else {
- $logSubject = '添加一个原味分类,分类名字:' . $inputData['name'];
- $logSvalue = $result->uid;
- $logDbData = [
- 'after_items' => [
- $result->toArray(),
- ],
- 'before_items' => [],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($result->uid);
- }
- }
- /**
- * 修改分类
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function categoryEdit(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'name' => 'nullable|string',
- 'status' => 'nullable|in:1,2',
- 'type' => 'nullable|in:1,2',
- 'sort' => 'nullable|integer',
- 'uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
- if (!$categoryInfo) {
- return json_fail('该类型不存在!');
- }
- $oldCategoryInfo = clone $categoryInfo;
- if (!empty($inputData['name'])) {
- $categoryInfo->name = $inputData['name'];
- }
- if (!empty($inputData['status'])) {
- $categoryInfo->status = $inputData['status'];
- }
- if (!empty($inputData['type'])) {
- $categoryInfo->type = $inputData['type'];
- }
- if (!empty($inputData['sort'])) {
- $categoryInfo->sort = $inputData['sort'];
- }
- $result = $categoryInfo->save();
- if (!$result) {
- return json_fail('修改失败');
- } else {
- $logSubject = '修改一个原味分类,名字:' . $oldCategoryInfo->name;
- $logSvalue = $oldCategoryInfo->uid;
- $logDbData = [
- 'after_items' => [
- $categoryInfo->toArray(),
- ],
- 'before_items' => [
- $oldCategoryInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($categoryInfo->uid);
- }
- }
- /**
- * 删除分类
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function categoryDelete(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $categoryInfo = make(OriginalClassRepository::class)->findBy('uid', $inputData['uid']);
- if (!$categoryInfo) {
- return json_fail('该类型不存在!');
- }
- $oldCategoryInfo = clone $categoryInfo;
- $result = $categoryInfo->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个类原味分类,名字:' . $oldCategoryInfo->name;
- $logSvalue = $oldCategoryInfo->manager_id;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldCategoryInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData['uid']);
- }
- }
- /**
- * 评价列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|void
- */
- public function assessLists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'page' => 'nullable|integer',
- 'page_size' => 'nullable|integer',
- 'buy_uid' => 'nullable|string',
- 'goods_name' => 'nullable|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(GoodsAssessRepository::class)->pushCriteria(new GoodsAssessCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new OriginaAssessListsResponse($res);
- }
- /**
- * 删除评论
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function assessDelete(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'uid' => 'nullable|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $goodsAssessInfo = make(GoodsAssessRepository::class)->findBy('uid', $inputData['uid']);
- if (!$goodsAssessInfo) {
- return json_fail('该评论不存在!');
- }
- $oldDoodsAssessInfo = $goodsAssessInfo;
- $result = $goodsAssessInfo->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个类原味分类,名字:' . $goodsAssessInfo->name;
- $logSvalue = $oldDoodsAssessInfo->manager_id;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldDoodsAssessInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData['uid']);
- }
- }
- /**
- * 订单列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|OriginaOrderListsResponse
- */
- public function orderLists(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(OriginalOrderRepository::class)->pushCriteria(new OriginalOrderCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new OriginaOrderListsResponse($res);
- }
- /**
- * 操作订单
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function orderUpdate(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $OriginalOrderRep = make(OriginalOrderRepository::class);
- $orderInfo = $OriginalOrderRep->findBy('uid', $inputData['uid']);
- if (!$orderInfo) {
- return json_fail('该订单不存在!');
- }
- $oldOrderInfo = clone $orderInfo;
- $msg = '订单状态改变, 订单号' . $oldOrderInfo->order_sn;
- if (!empty($inputData['order_status'])) {
- switch ($inputData['order_status']) {
- case 3:
- $msg = '待发货订单发货,订单号:' . $oldOrderInfo->order_sn;
- break;
- case 4:
- $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' => '商品很棒!'
- ];
- // 确认收货
- $res = $OriginalOrderRep->confirmReceipt($data);
- if (!$res) {
- return json_fail('确认收货失败');
- }
- $msg = '待收货订单确认收货,订单号:' . $oldOrderInfo->order_sn;
- break;
- }
- $orderInfo->order_status = $inputData['order_status'];
- }
- if (!empty($inputData['redund_status'])) {
- switch ($inputData['redund_status']) {
- case 3:
- $msg = '订单退款驳回,订单号:' . $oldOrderInfo->order_sn;
- $oldOrderInfo->order_status = 1;
- break;
- case 4:
- // 退款
- $res = $OriginalOrderRep->refund($oldOrderInfo->toArray());
- if (!$res) {
- return json_fail('退款失败');
- }
- $msg = '订单退款确认成功,订单号:' . $oldOrderInfo->order_sn;
- break;
- }
- $orderInfo->refund_end_time = date('Y-m-d H:i:s');
- $orderInfo->redund_status = $inputData['redund_status'];
- }
- if (!empty($inputData['denial_reason'])) {
- $orderInfo->denial_reason = $inputData['denial_reason'];
- }
- if (!empty($inputData['courier_number'])) {
- $orderInfo->courier_number = $inputData['courier_number'];
- }
- if (!empty($inputData['courier_firm'])) {
- $orderInfo->courier_firm = $inputData['courier_firm'];
- }
- if (!empty($inputData['logistics_info'])) {
- $orderInfo->logistics_info = $inputData['logistics_info'];
- }
- $result = $orderInfo->save();
- if (!$result) {
- return json_fail('操作成功');
- } else {
- $logSubject = $msg;
- $logSvalue = $oldOrderInfo->manager_id;
- $logDbData = [
- 'after_items' => [
- $orderInfo->toArray()
- ],
- 'before_items' => [
- $oldOrderInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData['uid']);
- }
- }
- /**
- * 店铺列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed
- */
- public function shopsList(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'title' => 'nullable|string',
- 'is_certified' => 'nullable|in:1,2',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(ShopsRepository::class)->pushCriteria(new ShopsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- foreach ($res->items() as &$val) {
- $val->province = substr($val->province,0,strlen($val->province) - 6);
- $val->city = substr($val->city,0,strlen($val->city) - 6);
- $val->region = substr($val->region,0,strlen($val->region) - 6);
- $val->user_nick = $val->user->nick;
- $val->cover64 = '';
- unset($val->user);
- }
- return json_success($res);
- }
- /**
- * 添加店铺
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function shopsAdd(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $userId = make(UserRepository::class)->findBy('code', $inputData['user_uid'], ['id']);
- if (empty($userId)) {
- return json_fail('绑定的用户不存在');
- }
- $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'],
- ];
- $result = make(ShopsRepository::class)->create($setArr);
- if (!$result) {
- return json_fail('添加失败');
- } else {
- $logSubject = '添加一个店铺:' . $inputData['title'];
- $logSvalue = $result->uid;
- $logDbData = [
- 'after_items' => [
- $result->toArray(),
- ],
- 'before_items' => [],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($result->uid);
- }
- }
- /**
- * 店铺修改
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function shopsEdit(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $shopsInfo = make(ShopsRepository::class)->findBy('uid', $inputData['user_uid']);
- if (empty($shopsInfo)) {
- return json_fail('店铺不存在');
- }
- $oldShopsInfo = clone $shopsInfo;
- if (!empty($inputData['title'])) {
- $shopsInfo->title = $inputData['title'];
- }
- if (!empty($inputData['credit_value'])) {
- $shopsInfo->credit_value = $inputData['credit_value'];
- }
- if (!empty($inputData['stor'])) {
- $shopsInfo->stor = $inputData['stor'];
- }
- if (!empty($inputData['steer_level'])) {
- $shopsInfo->steer_level = $inputData['steer_level'];
- }
- if (!empty($inputData['is_certified'])) {
- $shopsInfo->is_certified = $inputData['is_certified'];
- }
- if (!empty($inputData['cover'])) {
- $shopsInfo->cover = $inputData['cover'];
- }
- if (!empty($inputData['is_certified'])) {
- $shopsInfo->is_certified = $inputData['is_certified'];
- }
- if (!empty($inputData['delivery_address'])) {
- $shopsInfo->province = $inputData['delivery_address'][0] . '000000';
- $shopsInfo->city = $inputData['delivery_address'][1] . '000000';
- $shopsInfo->region = $inputData['delivery_address'][2] . '000000';
- }
- if (!empty($inputData['share_ratio'])) {
- $shopsInfo->share_ratio = $inputData['share_ratio'];
- }
- if (!empty($inputData['goods_count'])) {
- $shopsInfo->goods_count = $inputData['goods_count'];
- }
- if (!empty($inputData['goods_up_count'])) {
- $shopsInfo->goods_up_count = $inputData['goods_up_count'];
- }
- if (!empty($inputData['introduce'])) {
- $shopsInfo->introduce = $inputData['introduce'];
- }
- if (!empty($inputData['tg'])) {
- $shopsInfo->tg = $inputData['tg'];
- }
- if (!empty($inputData['qq'])) {
- $shopsInfo->qq = $inputData['qq'];
- }
- if (!empty($inputData['margin'])) {
- $shopsInfo->margin = $inputData['margin'];
- }
- $result = $shopsInfo->save();
- if (!$result) {
- return json_fail('操作失败');
- } else {
- $logSubject = $inputData['title'];
- $logSvalue = $oldShopsInfo->uid;
- $logDbData = [
- 'after_items' => [
- $shopsInfo->toArray()
- ],
- 'before_items' => [
- $oldShopsInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData['uid']);
- }
- }
- /**
- * 商品列表
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|OriginaGoodsListsResponse
- */
- public function goodsList(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'title' => 'nullable|string',
- 'sell_uid' => 'nullable|string',
- 'status' => 'nullable|in:1,2,3,4'
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(OriginalRepository::class)->pushCriteria(new GoodsCriteria($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- return new OriginaGoodsListsResponse($res);
- }
- /**
- * 添加商品
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse\
- */
- public function goodsAdd(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $result = make(OriginalRepository::class)->createOne($inputData);
- if (!$result) {
- return json_fail('添加失败');
- } else {
- $logSubject = '添加一个商品:' . $inputData['title'];
- $logSvalue = $result->uid;
- $logDbData = [
- 'after_items' => [
- $result->toArray(),
- ],
- 'before_items' => [],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($result->uid);
- }
- }
- public function goodsEdit(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $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',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $oldGoodsInfo = [];
- $goodsInfo = make(OriginalRepository::class)->updateOne($inputData, $oldGoodsInfo);
- if (!$goodsInfo) {
- return json_fail('修改失败失败');
- } else {
- $logSubject = '修改一个商品:' . $inputData['title'];
- $logSvalue = $oldGoodsInfo['uid'];
- $logDbData = [
- 'after_items' => [
- $goodsInfo
- ],
- 'before_items' => [
- $oldGoodsInfo,
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($goodsInfo->uid);
- }
- }
- /**
- * 删除商品
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed|PaymentSuccessUidResponse
- */
- public function shopsDelete(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'uid' => 'required|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $goodsInfo = make(OriginalRepository::class)->findBy('uid', $inputData['uid']);
- if (empty($goodsInfo)) {
- return json_fail('商品不存在');
- }
- $oldGoodsInfo = clone $goodsInfo;
- $result = $goodsInfo->delete();
- if (!$result) {
- return json_fail('删除失败');
- } else {
- $logSubject = '删除一个类原味分类,名字:' . $goodsInfo->title;
- $logSvalue = $oldGoodsInfo->uid;
- $logDbData = [
- 'after_items' => [
- ],
- 'before_items' => [
- $oldGoodsInfo->toArray(),
- ],
- ];
- $this->log($logSubject, $logSvalue, $logDbData);
- return new PaymentSuccessUidResponse($inputData['uid']);
- }
- }
- /**
- * 收货地址
- *
- * @param ValidatorFactoryInterface $validatorFactory
- * @return mixed
- */
- public function userAddress(ValidatorFactoryInterface $validatorFactory)
- {
- $inputData = $this->getJsonData();
- $rules = [
- 'user_uid' => 'nullable|string',
- 'name' => 'nullable|string',
- ];
- $validator = $validatorFactory->make($inputData, $rules);
- if ($validator->fails()) {
- // 如果有错误(可能是多个信息),这里只取第一个错误信息返回.
- return json_fail($validator->errors()->first());
- }
- $orders = [
- ['created_at', 'DESC'],
- ];
- $pageSize = $inputData['page_size'] ?? CommonConstant::PAGE_SIZE;
- if ($pageSize > 500) {
- $pageSize = CommonConstant::PAGE_SIZE;
- }
- $page = format_page($inputData['page'] ?? 1);
- $res = make(UserShippingAddressRepository::class)->pushCriteria(new UserShippingAddressCriterias($inputData))->pushCriteria(new OrderLimitCriteria($orders))->paginate($pageSize, ['*'], $page);
- foreach ($res->items() as &$value) {
- $value->user_nick = $value->user->nick;
- unset($value->user);
- }
- return json_success($res);
- }
- /**
- * 商品所需下拉
- *
- * @return mixed
- */
- public function getDown()
- {
- $res['category'] = make(OriginalCategoryRepository::class)->findAllBy('type', 1, ['uid', 'name'])->keyBy('uid');
- $res['shops'] = make(ShopsRepository::class)->findAllBy('is_certified', 2, ['uid', 'title'])->keyBy('uid');
- return json_success($res);
- }
- }
|