|
@@ -0,0 +1,108 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller\auction;
|
|
|
+
|
|
|
+
|
|
|
+use app\models\auction\Auction;
|
|
|
+use app\models\auction\AuctionBooking;
|
|
|
+use app\models\auction\AuctionOrder;
|
|
|
+use app\models\auction\AuctionProduct;
|
|
|
+use app\models\user\User;
|
|
|
+use app\models\user\UserBill;
|
|
|
+use app\Request;
|
|
|
+use Monolog\Handler\Curl\Util;
|
|
|
+use think\facade\Cache;
|
|
|
+use crmeb\services\{
|
|
|
+ CacheService,
|
|
|
+ ExpressService,
|
|
|
+ SystemConfigService,
|
|
|
+};
|
|
|
+use crmeb\services\UtilService;
|
|
|
+use crmeb\repositories\OrderRepository;
|
|
|
+
|
|
|
+
|
|
|
+class AuctionProductController
|
|
|
+{
|
|
|
+
|
|
|
+ * 获取商品列表
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function auction_product(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ [['page', 'd'], 0],
|
|
|
+ [['limit', 'd'], 0],
|
|
|
+ ['id'],
|
|
|
+ ['user']
|
|
|
+ ]);
|
|
|
+ if (!$data['id']) return app('json')->fail('数据传入错误');
|
|
|
+ return app('json')->successful(AuctionProduct::list($data, $request->uid()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 购买商品
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function purchase(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['product_id'],
|
|
|
+ ]);
|
|
|
+ if (!$data['product_id']) return app('json')->fail('数据传入错误');
|
|
|
+
|
|
|
+ $product = AuctionProduct::where('id', $data['product_id'])->find();
|
|
|
+ if ($product['uid'] == $request->uid()) return app('json')->fail('无法购买自己商品');
|
|
|
+ if ($product){
|
|
|
+ AuctionOrder::beginTrans();
|
|
|
+
|
|
|
+ $order = AuctionOrder::where('product_id', $data['product_id'])->whereBetweenTime('create_time', date('Y-m-d H:i:s', strtotime(date('Y-m-d'))), date('Y-m-d H:i:s', strtotime('+1 day')))->find();
|
|
|
+ if ($order){
|
|
|
+ return app('json')->fail('商品以卖出');
|
|
|
+ }
|
|
|
+ $res = AuctionOrder::create([
|
|
|
+ 'uid' => $request->uid(),
|
|
|
+ 'collection_id' => $product['uid'],
|
|
|
+ 'order_id' => getNewOrderId(),
|
|
|
+ 'name' => $product['name'],
|
|
|
+ 'product_id' => $product['id'],
|
|
|
+ 'image'=> $product['image'],
|
|
|
+ 'price' => $product['hanging_price'],
|
|
|
+ ]);
|
|
|
+ if ($res){
|
|
|
+ AuctionOrder::commitTrans();
|
|
|
+ return app('json')->successful('购买成功');
|
|
|
+ }else{
|
|
|
+ AuctionOrder::rollbackTrans();
|
|
|
+ return app('json')->fail('购买失败');
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return app('json')->fail('购买商品不存在');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function user_auction_order(Request $request)
|
|
|
+ {
|
|
|
+
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ [['type', 'd'], 1],
|
|
|
+ [['page', 'd'], 0],
|
|
|
+ [['limit', 'd'], 0],
|
|
|
+ ]);
|
|
|
+
|
|
|
+
|
|
|
+ return app('json')->successful(AuctionOrder::userOrder($data,$request->uid()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|