Browse Source

refill_buyback evidence merge

xiaoyu 3 years ago
parent
commit
ceeb1edcff

+ 45 - 5
admin/control/refill_order_manual.php

@@ -185,7 +185,7 @@ class refill_order_manualControl extends SystemControl
             }
         }
         elseif (in_array($oper_type, ['success', 'cancel', 'buyback'])) {
-            $this->manual_record($orders, $oper_type, $order_ids, $_GET['bz']);
+            $this->manual_record($orders, $oper_type, $order_ids, $_GET);
         }
         else {
             showMessage('手动操作类型错误');
@@ -193,10 +193,10 @@ class refill_order_manualControl extends SystemControl
         showMessage('操作成功');
     }
 
-    private function manual_record($orders, $oper_type, $order_ids, $bz)
+    private function manual_record($orders, $oper_type, $order_ids, $input)
     {
         $admininfo = $this->getAdminInfo();
-        $bz = empty($bz) ? '' : $bz;
+        $bz = empty($input['bz']) ? '' : $input['bz'];
 
         $buyback_ids = function ($order_ids, $oper_type) {
             $buybacks = Model('refill_buyback')->getBuyBackList(['order_id' => ['in', $order_ids], 'manual_type' => $oper_type]);
@@ -220,14 +220,21 @@ class refill_order_manualControl extends SystemControl
 
         if($oper_type == 'buyback')
         {
+            $merge = $input['merge'];
             $mchids = array_column($orders, 'mchid');
             $mchids = $this->unique_array($mchids);
+            if($merge > 0 && count($mchids) > 1) {
+                showMessage('下游机构多家时,返销记录不可合并');
+            }
             $merchant_list = $this->merchants(['mchid' => ['in', $mchids]]);
             foreach ($merchant_list as $merchant) {
                 $merchants[$merchant['mchid']] = $merchant;
             }
             $store_ids = array_column($orders, 'store_id');
             $store_ids = $this->unique_array($store_ids);
+            if($merge > 0 && count($store_ids) > 1) {
+                showMessage('上游通道多家时,返销记录不可合并');
+            }
             $provider_list = $this->providers(['refill_provider.store_id' => ['in', $store_ids]]);
             foreach ($provider_list as $provider) {
                 $providers[$provider['store_id']] = $provider;
@@ -242,6 +249,8 @@ class refill_order_manualControl extends SystemControl
         $cur_time = time();
         if($oper_type == 'buyback')
         {
+            $refill_evidence = [];
+            $provider_amount = [];
             foreach ($orders as $order)
             {
                 $order_id = intval($order['order_id']);
@@ -273,15 +282,37 @@ class refill_order_manualControl extends SystemControl
                     if($ret)
                     {
                         $merchant_bz = "机构:{$mchid},订单号:{$order['mch_order']},卡号:{$order['card_no']},返销退款:{$order['mch_amount']}";
-                        $this->ct_refill_evidence(['mch_amount' => $order['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
                         $this->credit_save_money($order['mch_amount'], 'add', $buyer_id, $merchant_bz);
+                        if ($merge > 0) {
+                            $refill_evidence['mchid'] = $mchid;
+                            if (!array_key_exists('mch_amount', $refill_evidence)) {
+                                $refill_evidence['mch_amount'] = $order['mch_amount'];
+                                $refill_evidence['count'] = 1;
+                            } else {
+                                $refill_evidence['mch_amount'] += $order['mch_amount'];
+                                $refill_evidence['count'] += 1;
+                            }
+                        } else {
+                            $this->ct_refill_evidence(['mch_amount' => $order['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
+                        }
                     }
 
                     if($ret)
                     {
                         $provider_bz = "通道:{$store_id},椰子单号:{$order['order_sn']},卡号:{$order['card_no']},返销退款:{$order['channel_amount']}";
-                        $this->ct_provider_amount(['channel_amount' => $order['channel_amount']], $provider_info, $cur_time, $admininfo);
                         $this->credit_save_money($order['channel_amount'], 'add', $account_id, $provider_bz);
+                        if($merge > 0) {
+                            $provider_amount['store_id'] = $store_id;
+                            if (!array_key_exists('channel_amount', $provider_amount)) {
+                                $provider_amount['channel_amount'] = $order['channel_amount'];
+                                $provider_amount['count'] = 1;
+                            } else {
+                                $provider_amount['channel_amount'] += $order['channel_amount'];
+                                $provider_amount['count'] += 1;
+                            }
+                        }else{
+                            $this->ct_provider_amount(['channel_amount' => $order['channel_amount']], $provider_info, $cur_time, $admininfo);
+                        }
                     }
 
                     $trans->commit();
@@ -291,6 +322,15 @@ class refill_order_manualControl extends SystemControl
                     Log::record("manual_record err: {$e->getMessage()}", Log::ERR);
                 }
             }
+            if(!empty($refill_evidence)) {
+                $merchant_bz = "机构:{$mchid},共返销单数:{$refill_evidence['count']},返销退款总金额:{$refill_evidence['mch_amount']}";
+                $merchant_info = $merchants[$refill_evidence['mchid']];
+                $this->ct_refill_evidence(['mch_amount' => $refill_evidence['mch_amount'], 'bz' => $merchant_bz], $merchant_info, $cur_time, $admininfo);
+            }
+            if(!empty($provider_amount)) {
+                $provider_info = $providers[$store_id];
+                $this->ct_provider_amount(['channel_amount' => $provider_amount['channel_amount']], $provider_info, $cur_time, $admininfo);
+            }
         }
         else
         {

+ 15 - 3
admin/templates/default/refill.order.batch.php

@@ -281,6 +281,17 @@
                         <span><i class="icon-edit"></i>批量返销</span>
                     </a>
                 </td>
+                <th></th>
+                <td></td>
+                <th><label class="query_ors">返销备注</label></th>
+                <td>
+                    <textarea name="bz" id="bz" cols="30" rows="10"></textarea>
+                </td>
+                <th><label style="width: 120px;">&nbsp;返销<br>(是否合并下游申请)</label></th>
+                <td>
+                    <input type="radio" name="merge" value="1">合并
+                    <input type="radio" name="merge" value="0" checked>不合并
+                </td>
             </tr>
         </table>
     </form>
@@ -577,6 +588,8 @@
                 btn: ['确定', '取消'],
                 title: '批量返销'
             }, function () {
+                let bz = $("textarea[name='bz']").val();
+                let merge = $("input[name='merge']:checked").val();
                 let arr = [];
                 $("input:checkbox:checked").each(function (i) {
                     arr[i] = $(this).val();
@@ -586,9 +599,9 @@
                 let number = Number(strr);
                 if (isNaN(number)) {
                     let strrr = str.substring(1, str.length);
-                    window.location.href = `index.php?act=refill_order_manual&op=refill_order_batch_dispose&type=buyback&order_id= ${strrr ? strrr : ''}`
+                    window.location.href = `index.php?act=refill_order_manual&op=refill_order_batch_dispose&type=buyback&order_id= ${strrr ? strrr : ''}&bz=${bz}&merge=${merge}`
                 } else if(!isNaN(number) && str !== '') {
-                    window.location.href = `index.php?act=refill_order_manual&op=refill_order_batch_dispose&type=buyback&order_id= ${str ? str : ''}`
+                    window.location.href = `index.php?act=refill_order_manual&op=refill_order_batch_dispose&type=buyback&order_id= ${str ? str : ''}&bz=${bz}&merge=${merge}`
                 } else {
                     layer.msg('请还没有任何操作,请先选择');
                 }
@@ -605,7 +618,6 @@
             }, function () {layer.msg('取消成功');});
         })
 
-        //返销
         $('.manual').click(function() {
             let type = $(this).attr('data-type');
             let data_id = $(this).attr('data-id');