fly 5 years ago
parent
commit
5a85028168

+ 114 - 59
app/Http/Controllers/QuickApp/Order/OrdersController.php

@@ -1,6 +1,7 @@
 <?php
 
 namespace App\Http\Controllers\QuickApp\Order;
+
 use App\Modules\Statistic\Services\AdVisitStatService;
 use App\Http\Controllers\QuickApp\BaseController;
 use Illuminate\Http\Request;
@@ -21,7 +22,10 @@ use Hashids;
 use EasyWeChat\Foundation\Application;
 use App\Modules\Product\Services\ProductService;
 use App\Modules\Book\Services\BookConfigService;
+use App\Modules\Book\Services\BookGiftsService;
 use App\Modules\Book\Services\BookService;
+use App\Modules\Channel\Services\PayTemplateService;
+use App\Modules\User\Services\UserDivisionCpcPropertyService;
 use Log;
 
 class OrdersController extends BaseController
@@ -30,6 +34,24 @@ class OrdersController extends BaseController
      * @apiDefine Order 订单
      */
 
+    /**
+     * 
+     */
+    private $chargeList;
+
+    public function exchangeList()
+    {
+        foreach ($this->chargeList as &$item) {
+            if (!$item->switch_to) continue;
+            $order = Order::where('uid', $this->uid)->where('status', 'PAID')->where('product_id', $item->id)->first();
+            if ($order) {
+                $change = ProductService::getProductSingle($item->switch_to);
+                $item->id = $change->id;
+                $item->price = $change->price;
+                $item->given = $change->given;
+            }
+        }
+    }
 
     /**
      * @apiVersion 1.0.0
@@ -97,73 +119,106 @@ class OrdersController extends BaseController
      */
     public function chargeList(Request $request)
     {
-        $res = ProductService::getChargeProduct();
-        if (!$res->isEmpty()) {
-            $data = [];
-            foreach ($res as $v) {
-                $intro = [];
-                if ($v->given > 0 && $v->type == 'TICKET_RECHARGE') {
-                    $intro = [
-                        [
-                            'label' => ($v->price * 100) . "+",
-                            'important' => false,
-                        ],
-                        [
-                            'label' => $v->given,
-                            'important' => true,
-                        ],
-                        [
-                            'label' => '书币',
-                            'important' => false,
-                        ]
+        $bid = $request->input('bid', '');
+        $temp = $bid;
+        $template_id = PayTemplateService::getPayTemplate($this->distribution_channel_id);
+        $book_config = null;
+        if ($bid) {
+            $bid = Hashids::decode($bid)[0];
+            $book_config = BookConfigService::getBookById($bid);
+        }
+        if ($template_id == 2) { //模板2只有在长篇小说过来的用户才显示
+            //部分渠道需要2元模板不管哪个入口进来都展示
+            $exclude_channels = explode(',', env('PRICE_TWO_SHOW_ALL_CHANNEL'));
+            if (!in_array($this->distribution_channel_id, $exclude_channels)) {
+                if ($book_config) {
+                    if ($book_config->charge_type == 'BOOK') $template_id = 1;
+                }
+            }
+        }
 
-                    ];
-                    $intro2 = [
-                        ['label' => '多送', 'important' => false],
-                        ['label' => (int) ($v->given / 100), 'important' => true],
-                        ['label' => '元', 'important' => false],
-                    ];
-                    $v->vip = 0;
+        $res = ProductService::getChargeProduct($template_id);
+        if (!$res) {
+            return response()->error('WAP_SYS_ERROR');
+        }
+        $this->chargeList = $res;
+        $this->exchangeList();
+        //TODO 长篇小数才有模板2
+        $uid = $this->uid;
+        $is_first_recharge = OrderService::judgeUserFirstRecharge($uid);
+
+        $data = [];
+        $appad = 0;
+
+        foreach ($res as $v) {
+            if ($template_id == 7 && $book_config && $book_config->charge_type == 'BOOK' && $v->price == 2) {
+                continue;
+            }
+            if ($template_id == 2 && $v->type == 'NEW_USER' && !$bid) {
+                //2元模版,直接进充值,不出现
+                continue;
+            }
+            if ($v->type == 'NEW_USER' && $is_first_recharge) {
+                if (
+                    env('NO_NEW_USER_CHARGE') &&
+                    in_array(
+                        $this->distribution_channel_id,
+                        explode(',', env('NO_NEW_USER_CHARGE'))
+                    )
+                ) {
+                    continue;
+                }
+                $temp = [
+                    'price' => (float) $v->price . '元',
+                    'is_year_order' => 0,
+                    'is_month_order' => 0,
+                    'text' => sprintf('%s+%s书币', $v->price * 100, $v->given),
+                    'first_charge' => true,
+                    'save_text' => round($v->given / 100, 1) . '元',
+                    'product_id' => $v->id,
+                ];
+                $data[] = $temp;
+            } elseif ($v->type == 'YEAR_ORDER') {
+                if ($v->type == 'NEW_USER') {
+                    continue;
                 }
-                if ($v->given == 0 && $v->type == 'TICKET_RECHARGE') {
-                    $intro = [
-                        [
-                            'label' => $v->price * 100,
-                            'important' => false,
-                        ],
-                        [
-                            'label' => '书币',
-                            'important' => false,
-                        ]
-                    ];
-                    $v->vip = 0;
-                    $intro2 = [];
+                $save_text = '年费vip会员';
+                $text = '每天1元,全年免费看';
+                $temp = [
+                    'price' => (int) $v->price . '元',
+                    'is_year_order' => 1,
+                    'is_month_order' => 0,
+                    'text' => $text,
+                    'first_charge' => false,
+                    'save_text' => $save_text,
+                    'product_id' => $v->id,
+                ];
+                $data[] = $temp;
+            }else {
+                if ($v->type == 'NEW_USER') {
+                    continue;
                 }
-                if ($v->given == 0 && $v->type == 'YEAR_ORDER') {
-                    $intro = [
-                        [
-                            'label' => '年费VIP会员',
-                            'important' => true,
-                        ]
-                    ];
-                    $v->vip = 1;
-                    $intro2 = [
-                        ['label' => '每天1元,全年免费看', 'important' => false],
-                    ];
+                $save_text = '';
+                if ($v->given) {
+                    $save_text = round($v->given / 100, 1) . '元';
+                    $text = sprintf('%s+%s书币', $v->price * 100, $v->given);
+                } else {
+                    $text = sprintf('%s书币', $v->price * 100);
                 }
-                $data[] = [
+
+                $temp = [
+                    'price' => (float) $v->price . '元',
+                    'is_year_order' => 0,
+                    'is_month_order' => 0,
+                    'text' => $text,
+                    'first_charge' => false,
+                    'save_text' => $save_text,
                     'product_id' => $v->id,
-                    'price' => (int) $v->price . '元',
-                    'vip' => $v->vip,
-                    'intro' => $intro,
-                    'intro2' => $intro2,
-                    'is_default' => $v->is_default,
                 ];
+                $data[] = $temp;
             }
-            return response()->success($data);
-        } else {
-            return response()->error('QAPP_SYS_ERROR');
         }
+        return response()->success($data);
     }
 
 

+ 4 - 4
app/Http/Controllers/QuickApp/User/UserController.php

@@ -47,10 +47,10 @@ class UserController extends BaseController
      *             "province": "浙江省",
      *             "city": "杭州",
      *             "country": "中国",
-     *             "headimgurl": "http://.."
-     *             "send_order_id": 323
-     *             "balance": 8956
-     *             "register_time": "2017-12-12 12:12:12"
+     *             "headimgurl": "http://..",
+     *             "send_order_id": 323,
+     *             "balance": 8956,
+     *             "register_time": "2017-12-12 12:12:12",
      *         }
      *     }
      */