Taskorderguquan.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. <?php
  2. /**
  3. * @package merchant
  4. * @Author: Qinii
  5. * @Date: 2020/5/28
  6. */
  7. namespace app\controller\api\store\merchant;
  8. use app\common\model\user\User;
  9. use think\facade\Db;
  10. class Taskorderguquan
  11. {
  12. public function assignment()
  13. {
  14. $result = [
  15. 'oldOrderExistGongXian' => [],
  16. 'orderExistGongXian' => [],
  17. 'oldOrderExistPv' => [],
  18. 'orderExistPv' => [],
  19. 'gongXianDataOldList' => [],
  20. 'gongXianDataList' => [],
  21. 'pvDataOldList' => [],
  22. 'pvDataList' => [],
  23. 'contributeNot' => [],
  24. 'pvNot' => [],
  25. 'userUpdateSummary' => ['success' => 0, 'failed' => 0, 'skipped' => 0], // 优化: 汇总用户更新结果
  26. 'insertGongXianSummary' => ['success' => 0, 'failed' => 0], // 优化: 汇总贡献插入结果
  27. 'insertPvSummary' => ['success' => 0, 'failed' => 0], // 优化: 汇总PV插入结果
  28. 'errors' => [], // 优化: 统一记录错误信息
  29. ];
  30. // --- 数据库查询部分 (保持不变,已优化) ---
  31. // 1. 查询用户
  32. $userList = Db::name("user")
  33. ->where('is_del', 0)
  34. // ->whereIn('uid', [277, 1593])
  35. ->column('uid, spread_uid, contribute, per_contribute, pv', 'uid');
  36. // $userIds = array_keys($userList);
  37. $oldUserList = Db::name("old_user_jbp")
  38. ->column('id, amount');
  39. // 2. 查询老订单
  40. $userOfGoodsListRaw = Db::name("old_user_of_goods")
  41. ->where('status', 1)
  42. // 优化: 如果用户量大,可以考虑只查相关用户的订单
  43. // ->whereIn('user_id', $userIds)
  44. ->field('user_id, money, order_id, create_time')
  45. ->select()
  46. ->toArray();
  47. // 3. 查询新订单
  48. $storeOrderListRaw = Db::name("store_order")
  49. ->whereIn('status', [0, 1, 2, 3])
  50. // 优化: 如果用户量大,可以考虑只查相关用户的订单
  51. // ->whereIn('uid', $userIds)
  52. ->field('uid, pay_price, mer_id, status, order_id, create_time')
  53. ->select()
  54. ->toArray();
  55. // 4. 查询已存在的贡献值记录
  56. $gongXianListRaw = Db::name("user_sign_gongxian")
  57. ->where('status', '<>', -1)
  58. // 优化: 如果记录非常多,可以分批查询或只查相关用户的
  59. // ->whereIn('uid', array_merge($userIds, array_column($userList, 'spread_uid'))) // 查询购买者和潜在推广者
  60. ->field('uid, order_id, number, status, type')
  61. ->select()
  62. ->toArray();
  63. // 5. 查询已存在的PV记录
  64. $pvListRaw = Db::name("user_pv_log")
  65. ->where('status', '<>', -1)
  66. // 优化: 同上
  67. // ->whereIn('uid', $userIds)
  68. ->field('uid, order_id, pv, status')
  69. ->select()
  70. ->toArray();
  71. // --- 数据预处理部分
  72. $existingGongXian = [];
  73. $existingGongXianByUid = [];
  74. foreach ($gongXianListRaw as $gx) {
  75. $existingGongXian[$gx['uid'] . '_' . $gx['order_id']] = ['number' => $gx['number'], 'status' => $gx['status'], 'type' => $gx['type']];
  76. // TODO 目前老订单id 1-900 新订单ID 4868 - 6255 线下扫码订单 6870 - 8733
  77. if ((1 <= $gx['order_id'] && $gx['order_id'] <= 900) || (4868 <= $gx['order_id'] && $gx['order_id'] <= 6869)) {
  78. $existingGongXianByUid[$gx['uid']][] = $gx['order_id'];
  79. }
  80. }
  81. unset($gongXianListRaw);
  82. $existingPv = [];
  83. $existingPvByUid = [];
  84. foreach ($pvListRaw as $pv) {
  85. $existingPv[$pv['uid'] . '_' . $pv['order_id']] = ['pv' => $pv['pv'], 'status' => $pv['status']];
  86. // TODO 目前老订单id 1-900 新订单ID 4868 - 6255 线下扫码订单 6870 - 8733
  87. if ((1 <= $pv['order_id'] && $pv['order_id'] <= 900) || (4868 <= $pv['order_id'] && $pv['order_id'] <= 6869)) {
  88. $existingPvByUid[$pv['uid']][] = $pv['order_id'];
  89. }
  90. }
  91. unset($pvListRaw);
  92. $userOfGoodsByUid = [];
  93. foreach ($userOfGoodsListRaw as $oldOrder) $userOfGoodsByUid[$oldOrder['user_id']][] = $oldOrder;
  94. unset($userOfGoodsListRaw);
  95. $storeOrdersByUid = [];
  96. foreach ($storeOrderListRaw as $order) $storeOrdersByUid[$order['uid']][] = $order;
  97. unset($storeOrderListRaw);
  98. // *** 主逻辑处理与数据收集 ***
  99. $gongXianDataToInsert = []; // 优化: 合并新旧贡献插入列表
  100. $pvDataToInsert = []; // 优化: 合并新旧PV插入列表
  101. $userUpdateData = []; // 优化: 收集所有需要更新的用户数据 [uid => ['contribute'=>float, 'pv'=>float, 'per_contribute'=>float]]
  102. // 初始化所有用户的待更新数据
  103. foreach ($userList as $uid => $user) {
  104. // 预先设置初始值,确保即使没有订单的用户也能被包含在后续可能的更新逻辑中(如果需要)
  105. // 如果用户没有任何订单,他们的 contribute 和 pv 应该保持数据库原始值或根据业务逻辑设为0
  106. // 这里我们先假设如果没有订单,他们的计算值就是0
  107. $userUpdateData[$uid] = [
  108. 'uid' => $uid,
  109. 'contribute' => 0.0,
  110. 'pv' => 0.0,
  111. 'per_contribute' => 0.0,
  112. ];
  113. // 初始化推广者的 per_contribute 累加器
  114. if (!empty($user['spread_uid'])) {
  115. $spreadUid = $user['spread_uid'];
  116. if (!isset($userUpdateData[$spreadUid])) {
  117. if (isset($userList[$spreadUid])) {
  118. if (!isset($userUpdateData[$spreadUid]['per_contribute'])) {
  119. $userUpdateData[$spreadUid]['per_contribute'] = 0.0; // 初始化推广者的累加
  120. }
  121. } else {
  122. // 记录或处理推广者不在当前用户列表的情况
  123. $result['errors'][] = "执行{$uid}时,没找到 推荐人 {$spreadUid}";
  124. // 可以选择跳过给这个推广者增加 per_contribute
  125. }
  126. } else if (!isset($userUpdateData[$spreadUid]['per_contribute'])) {
  127. $userUpdateData[$spreadUid]['per_contribute'] = 0.0; // 初始化推广者的累加
  128. }
  129. }
  130. }
  131. // 遍历用户列表进行计算和数据收集
  132. foreach ($userList as $uid => $user) {
  133. $spreadUid = $user['spread_uid'];
  134. $existingGongXianByUid[$uid] = $existingGongXianByUid[$uid] ?? [];
  135. $existingPvByUid[$uid] = $existingPvByUid[$uid] ?? [];
  136. if (isset($userOfGoodsByUid[$uid])) {
  137. foreach ($userOfGoodsByUid[$uid] as $oldOrder) {
  138. switch ($oldOrder['money']) {
  139. case 1180:
  140. $totalPv = 700.0;
  141. break;
  142. case 11800:
  143. $totalPv = 7000.0;
  144. break;
  145. case 10620:
  146. $totalPv = 6300.0;
  147. break;
  148. case 2360:
  149. $totalPv = 1400.0;
  150. break;
  151. case 9440:
  152. $totalPv = 5600.0;
  153. break;
  154. default:
  155. $totalPv = round($oldOrder['money'] * 0.7, 2);
  156. break;
  157. }
  158. $settlementTimeOld = $oldOrder['create_time'] ? date('Y-m-d H:i:s', $oldOrder['create_time']) : strtotime($user['create_time']);
  159. // --- 收集贡献值插入数据 ---
  160. $orderKey = $uid . '_' . $oldOrder['order_id'];
  161. // 一个人 同一个订单 可能有多条记录 有问题
  162. if (isset($existingGongXian[$orderKey])) {
  163. $result['oldOrderExistGongXian'][] = ['uid' => $uid, 'order_id' => $oldOrder['order_id']];
  164. $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$oldOrder['order_id']]);
  165. if ($existingGongXian[$orderKey]['status'] == 1) {
  166. if ($existingGongXian[$orderKey]['type'] == 1) {
  167. $userUpdateData[$uid]['contribute'] += $existingGongXian[$orderKey]['number'];
  168. } else if ($existingGongXian[$orderKey]['type'] == 2) {
  169. $userUpdateData[$uid]['contribute'] -= $existingGongXian[$orderKey]['number'];
  170. }
  171. }
  172. if (!empty($spreadUid) && isset($userUpdateData[$spreadUid])) {
  173. $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$oldOrder['order_id']]);
  174. if (isset($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']])) {
  175. if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['status'] == 1) {
  176. if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['type'] == 1) {
  177. $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['number'];
  178. } else if ($existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['type'] == 2) {
  179. $userUpdateData[$spreadUid]['per_contribute'] -= $existingGongXian[$spreadUid . '_' . $oldOrder['order_id']]['number'];
  180. }
  181. }
  182. }
  183. }
  184. } else {
  185. if ($totalPv > 0) {
  186. $userUpdateData[$uid]['contribute'] += $totalPv;
  187. // --- 收集贡献值插入数据 ---
  188. $gongXianBase = [
  189. "number" => $totalPv, "addtime" => strtotime($settlementTimeOld), "status" => 1,
  190. "order_type" => 21, "order_id" => $oldOrder['order_id'],
  191. "desc" => '', "surplus" => 0, "type" => 1, 'settlement_time' => $settlementTimeOld
  192. ];
  193. // 本人
  194. $gongXianDataToInsert[] = array_merge(["uid" => $uid, "mark" => "购买会员专区商品赠送贡献值(1.0)"], $gongXianBase);
  195. $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$oldOrder['order_id']]);
  196. // 推广人
  197. if (!empty($user['spread_uid'])) {
  198. if (isset($userUpdateData[$spreadUid])) {
  199. $userUpdateData[$spreadUid]['per_contribute'] += $totalPv;
  200. $gongXianDataToInsert[] = array_merge(["uid" => $spreadUid, "mark" => "推广会员专区商品赠送贡献值(1.0)"], $gongXianBase);
  201. $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$oldOrder['order_id']]);
  202. }
  203. }
  204. }
  205. }
  206. // --- 收集 PV 插入数据 ---
  207. if (isset($existingPv[$orderKey])) {
  208. $result['oldOrderExistPv'][] = ['uid' => $uid, 'order_id' => $oldOrder['order_id']];
  209. if ($existingPv[$orderKey]['status'] == 1) {
  210. $userUpdateData[$uid]['pv'] += $existingPv[$orderKey]['pv'];
  211. }
  212. } else {
  213. $userUpdateData[$uid]['pv'] += $totalPv;
  214. $pvDataToInsert[] = [
  215. "uid" => $uid, "pv" => $totalPv, "addtime" => strtotime($settlementTimeOld), "status" => 1,
  216. "order_type" => 21, "order_id" => $oldOrder['order_id'],
  217. "mark" => "购买会员专区商品赠送PV(1.0)", 'settlement_time' => $settlementTimeOld
  218. ];
  219. }
  220. if (!empty($existingPvByUid[$uid])) {
  221. $existingPvByUid[$uid] = array_diff($existingPvByUid[$uid], [$oldOrder['order_id']]);
  222. }
  223. }
  224. } // end if isset($userOfGoodsByUid[$uid])
  225. // --- 处理新订单 ---
  226. if (isset($storeOrdersByUid[$uid])) {
  227. foreach ($storeOrdersByUid[$uid] as $order) {
  228. $totalPv = 0.0;
  229. // ... (if/else logic and switch case for $totalPv calculation - same as before)
  230. if ($order['mer_id'] == 496) {
  231. switch ($order['pay_price']) {
  232. case 1180:
  233. $totalPv = 700.0;
  234. break;
  235. case 11800:
  236. $totalPv = 7000.0;
  237. break;
  238. case 10620:
  239. $totalPv = 6300.0;
  240. break;
  241. case 2360:
  242. $totalPv = 1400.0;
  243. break;
  244. case 9440:
  245. $totalPv = 5600.0;
  246. break;
  247. default:
  248. $totalPv = round($order['pay_price'] * 0.7, 2);
  249. break;
  250. }
  251. } else if ($order['status'] == 3) {
  252. $totalPv = round($order['pay_price'] * 0.7, 2);
  253. }
  254. // --- 收集贡献值插入数据 ---
  255. $orderKey = $uid . '_' . $order['order_id'];
  256. $settlementTimeNew = $order['create_time'] ?: date('Y-m-d H:i:s', $user['create_time']);
  257. // --- 收集贡献值插入数据 ---
  258. if (isset($existingGongXian[$orderKey])) {
  259. $result['orderExistGongXian'][] = ['uid' => $uid, 'order_id' => $order['order_id']];
  260. $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$order['order_id']]);
  261. // 累加计算值
  262. if ($existingGongXian[$orderKey]['status'] == 1) {
  263. if ($existingGongXian[$orderKey]['type'] == 1) {
  264. $userUpdateData[$uid]['contribute'] += $existingGongXian[$orderKey]['number'];
  265. } else if ($existingGongXian[$orderKey]['type'] == 2) {
  266. $userUpdateData[$uid]['contribute'] -= $existingGongXian[$orderKey]['number'];
  267. }
  268. }
  269. if (!empty($spreadUid) && isset($userUpdateData[$spreadUid])) {
  270. $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$order['order_id']]);
  271. if (isset($existingGongXian[$spreadUid . '_' . $order['order_id']])) {
  272. if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['status'] == 1) {
  273. if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['type'] == 1) {
  274. $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $order['order_id']]['number'];
  275. } else if ($existingGongXian[$spreadUid . '_' . $order['order_id']]['type'] == 2) {
  276. $userUpdateData[$spreadUid]['per_contribute'] += $existingGongXian[$spreadUid . '_' . $order['order_id']]['number'];
  277. }
  278. }
  279. }
  280. }
  281. } else {
  282. if ($totalPv > 0) {
  283. $userUpdateData[$uid]['contribute'] += $totalPv;
  284. $gongXianBase = [ // 优化: 提取公共字段
  285. "number" => $totalPv, "addtime" => strtotime($settlementTimeNew), "status" => 1,
  286. "order_type" => 22, "order_id" => $order['order_id'],
  287. "desc" => '', "surplus" => 0, "type" => 1, 'settlement_time' => $settlementTimeNew
  288. ];
  289. // 本人
  290. $gongXianDataToInsert[] = array_merge(["uid" => $uid, "mark" => "购买商品赠送贡献值(2.0)"], $gongXianBase);
  291. $existingGongXianByUid[$uid] = array_diff($existingGongXianByUid[$uid], [$order['order_id']]);
  292. // 推广人
  293. if (!empty($user['spread_uid'])) {
  294. $spreadUid = $user['spread_uid'];
  295. if (isset($userUpdateData[$spreadUid])) { // 确保推广者存在
  296. $gongXianDataToInsert[] = array_merge(["uid" => $spreadUid, "mark" => "推广商品赠送贡献值(2.0)"], $gongXianBase);
  297. $userUpdateData[$spreadUid]['per_contribute'] += $totalPv; // 累加推广者业绩
  298. $existingGongXianByUid[$spreadUid] = array_diff($existingGongXianByUid[$spreadUid], [$order['order_id']]);
  299. }
  300. }
  301. }
  302. }
  303. // --- 收集 PV 插入数据 ---
  304. if (isset($existingPv[$orderKey])) {
  305. $result['orderExistPv'][] = ['uid' => $uid, 'order_id' => $order['order_id']];
  306. if ($existingPv[$orderKey]['status'] == 1) {
  307. $userUpdateData[$uid]['pv'] += $existingPv[$orderKey]['pv'];
  308. }
  309. } else {
  310. $userUpdateData[$uid]['pv'] += $totalPv;
  311. $pvDataToInsert[] = [
  312. "uid" => $uid, "pv" => $totalPv, "addtime" => strtotime($settlementTimeNew), "status" => 1,
  313. "order_type" => 22, // 确认 PV log 的 order_type 是否与贡献一致或有区分
  314. "order_id" => $order['order_id'],
  315. "mark" => "购买商品赠送PV(2.0)", // 标记调整为更通用
  316. 'settlement_time' => $settlementTimeNew
  317. ];
  318. }
  319. if (!empty($existingPvByUid[$uid])) {
  320. $existingPvByUid[$uid] = array_diff($existingPvByUid[$uid], [$order['order_id']]);
  321. }
  322. }
  323. }
  324. // end if isset($storeOrdersByUid[$uid])
  325. // --- 比较计算值与原值 (移到循环外处理) ---
  326. // (在此处比较并记录到 $result['contributeNot'] / $result['pvNot'])
  327. // 注意:浮点数比较可能需要容差
  328. $tolerance = 0.001; // 定义一个小的容差值
  329. if (abs($userUpdateData[$uid]['contribute'] - (float)$user['contribute']) > $tolerance) {
  330. $result['contributeNot'][] = [
  331. 'uid' => $uid,
  332. 'contribute_old' => (float)$user['contribute'], // 显式转换
  333. 'contribute_new' => $userUpdateData[$uid]['contribute']
  334. ];
  335. }
  336. if (abs($userUpdateData[$uid]['pv'] - (float)$user['pv']) > $tolerance) {
  337. $result['pvNot'][] = [
  338. 'uid' => $uid,
  339. 'pv_old' => (float)$user['pv'], // 显式转换
  340. 'pv_new' => $userUpdateData[$uid]['pv']
  341. ];
  342. }
  343. // per_contribute 是累加的,不需要与旧值比较,直接更新
  344. } // end foreach ($userList as $uid => $user)
  345. // *** 数据库批量操作 ***
  346. // 使用事务确保数据一致性
  347. Db::startTrans();
  348. try {
  349. $bill = [];
  350. foreach ($oldUserList as $item) {
  351. $bill[] = [
  352. 'uid' => $item['id'],
  353. 'link_id' => 0,//关联订单id
  354. 'pm' => 1,//0:支出,1:获得
  355. 'title' => '佣金',//账单标题
  356. 'category' => 'now_money',//明细种类
  357. 'type' => 'commission',//明细类型
  358. 'number' => $item['amount'],//明细数字
  359. 'balance' => 0,//剩余
  360. 'mark' => '1.0佣金记录',//备注
  361. 'create_time' => '2025-02-04 00:00:00',//添加时间
  362. 'status' => 1,//0待确定,1有效,-1无效
  363. 'commission_type' => 21,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
  364. //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
  365. //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
  366. 'order_sn' => 0,//订单号
  367. 'tripartite' => 0,//
  368. 'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
  369. 'mer_id' => 0,//商户id
  370. 'source' => 0,//1线下 0线上
  371. 'order_type' => 1,//1自营 2 第三方 订单类型
  372. 'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
  373. 'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
  374. 'take_time' => '',//结算时间
  375. 'district_id' => '',//
  376. 'street_id' => '',//
  377. 'month' => '',//月份
  378. ];
  379. }
  380. $chunkedBill = array_chunk($bill, 500);
  381. foreach ($chunkedBill as $chunk) {
  382. Db::name('user_bill')->insertAll($chunk);
  383. }
  384. if (!empty($existingGongXianByUid)) {
  385. foreach ($existingGongXianByUid as $uid => $orderList) {
  386. if (!empty($orderList)) {
  387. Db::name("user_sign_gongxian")
  388. ->where('uid', $uid)
  389. ->whereIn('order_id', $orderList)
  390. ->update(['status' => 0]);
  391. }
  392. }
  393. }
  394. if (!empty($existingPvByUid)) {
  395. foreach ($existingPvByUid as $uid => $orderList) {
  396. if (!empty($orderList)) {
  397. Db::name("user_pv_log")
  398. ->where('uid', $uid)
  399. ->whereIn('order_id', $orderList)
  400. ->update(['status' => 0]);
  401. }
  402. }
  403. }
  404. // --- 批量插入贡献值 ---
  405. if (!empty($gongXianDataToInsert)) {
  406. // 分块插入,避免单次插入过多数据 (例如一次500条)
  407. $chunkedGongXian = array_chunk($gongXianDataToInsert, 500);
  408. foreach ($chunkedGongXian as $chunk) {
  409. $insertedGongXianCount = Db::name('user_sign_gongxian')->insertAll($chunk);
  410. $result['insertGongXianSummary']['success'] += $insertedGongXianCount;
  411. }
  412. if ($result['insertGongXianSummary']['success'] < count($gongXianDataToInsert)) {
  413. $result['insertGongXianSummary']['failed'] = count($gongXianDataToInsert) - $result['insertGongXianSummary']['success'];
  414. // 可以考虑记录更详细的失败信息,但这比较复杂,需要知道哪些失败了
  415. $result['errors'][] = "GongXian insertion partially failed or failed completely.";
  416. // 根据业务决定是否回滚
  417. // throw new Exception("GongXian insertion failed");
  418. }
  419. } else {
  420. $result['insertGongXianSummary']['skipped'] = true; // 标记为跳过(无数据)
  421. }
  422. // --- 批量插入PV ---
  423. if (!empty($pvDataToInsert)) {
  424. $chunkedPv = array_chunk($pvDataToInsert, 500);
  425. foreach ($chunkedPv as $chunk) {
  426. $insertedPvCount = Db::name('user_pv_log')->insertAll($chunk);
  427. $result['insertPvSummary']['success'] += $insertedPvCount;
  428. }
  429. if ($result['insertPvSummary']['success'] < count($pvDataToInsert)) {
  430. $result['insertPvSummary']['failed'] = count($pvDataToInsert) - $result['insertPvSummary']['success'];
  431. $result['errors'][] = "PV Log insertion partially failed or failed completely.";
  432. // throw new Exception("PV Log insertion failed");
  433. }
  434. } else {
  435. $result['insertPvSummary']['skipped'] = true; // 标记为跳过(无数据)
  436. }
  437. // --- 批量更新用户信息 ---
  438. $usersToUpdate = [];
  439. // 筛选出实际需要更新的用户数据 (值有变化或 per_contribute > 0)
  440. foreach ($userUpdateData as $uid => $updateInfo) {
  441. $originalUser = $userList[$uid]; // 获取原始用户信息
  442. // 检查 contribute 或 pv 是否变化(使用容差),或者 per_contribute 是否需要更新
  443. $needsUpdate = false;
  444. if (abs($updateInfo['contribute'] - (float)$originalUser['contribute']) > $tolerance) $needsUpdate = true;
  445. if (abs($updateInfo['pv'] - (float)$originalUser['pv']) > $tolerance) $needsUpdate = true;
  446. // per_contribute 始终更新,因为它是在现有基础上累加的(除非业务定义不同)
  447. // 如果 per_contribute 数据库设计是直接覆盖,那只有 > 0 时才需要更新
  448. // 假设是覆盖更新,且只有大于0时才需要更新变动(如果一直是0则不用更新)
  449. if ($updateInfo['per_contribute'] > 0.0) { // 只有当推广业绩>0时才触发更新
  450. // 这里需要确认 per_contribute 是覆盖还是累加?
  451. // 如果是数据库累加: Db::name("user")->where('uid', $uid)->inc('per_contribute', $amount)->update(); 需要单独处理
  452. // 如果是覆盖: 直接放入 saveAll
  453. // 假设是覆盖,我们只更新有变化的或per_contribute > 0 的
  454. $needsUpdate = true;
  455. } else {
  456. // 如果 per_contribute 计算结果为0,且 contribute 和 pv 也未变,则不需要更新 per_contribute 字段
  457. unset($updateInfo['per_contribute']); // 移除无需更新的 per_contribute
  458. if (empty($updateInfo)) $needsUpdate = false; // 如果移除后为空,则不更新
  459. }
  460. if ($needsUpdate) {
  461. // 确保只包含需要更新的字段,并且包含主键 'uid'
  462. $finalUpdateData = ['uid' => $uid];
  463. if (isset($updateInfo['contribute'])) $finalUpdateData['contribute'] = $updateInfo['contribute'];
  464. if (isset($updateInfo['pv'])) $finalUpdateData['pv'] = $updateInfo['pv'];
  465. if (isset($updateInfo['per_contribute']) && $updateInfo['per_contribute'] > 0.0) { // 再次确认只更新大于0的推广业绩
  466. $finalUpdateData['per_contribute'] = $updateInfo['per_contribute'];
  467. }
  468. if (count($finalUpdateData) > 1) { // 确保除了uid还有其他字段要更新
  469. $usersToUpdate[] = $finalUpdateData;
  470. } else {
  471. $result['userUpdateSummary']['skipped']++; // 记录跳过的更新(无变化)
  472. }
  473. } else {
  474. $result['userUpdateSummary']['skipped']++; // 记录跳过的更新(无变化)
  475. }
  476. }
  477. if (!empty($usersToUpdate)) {
  478. // 使用 saveAll 进行批量更新 (要求 PHP >= 7.1.8 for MySQL)
  479. // saveAll 会根据主键 'uid' 更新对应记录
  480. $userModel = new User();
  481. $updatedCount = $userModel->saveAll($usersToUpdate); // TP6 支持 saveAll
  482. // 注意: saveAll 返回的是成功保存或更新的 *对象集合* 或 *布尔值*,不是影响的行数。
  483. // 需要检查返回类型并判断成功数量。通常返回集合时 count(集合) 是成功数。
  484. // 如果是 TP5,可能需要循环 update 或构造复杂 SQL。
  485. // 假设 TP6 saveAll 成功会返回包含更新后数据的集合或true,失败是false
  486. if ($updatedCount !== false) {
  487. // 这里需要一种方法来确定实际更新了多少条记录。
  488. // saveAll 的返回值可能需要进一步处理。
  489. // 简单假设:如果返回不是 false,就认为请求中的都成功了(可能不准确)
  490. // 更精确的方法是 saveAll 后再查询一次确认。
  491. // 这里我们暂时认为 saveAll 返回非 false 即为大部分成功
  492. $result['userUpdateSummary']['success'] = count($usersToUpdate); // 乐观估计
  493. } else {
  494. $result['userUpdateSummary']['failed'] = count($usersToUpdate); // 全部失败
  495. $result['errors'][] = "User batch update failed using saveAll.";
  496. // throw new Exception("User batch update failed");
  497. }
  498. }
  499. // 更新统计:失败数等于总数减去成功和跳过的
  500. //$result['userUpdateSummary']['failed'] = count($userList) - $result['userUpdateSummary']['success'] - $result['userUpdateSummary']['skipped'];
  501. // 如果所有操作都成功,提交事务
  502. Db::commit();
  503. } catch
  504. (\Exception $e) {
  505. // 如果任何数据库操作失败,回滚事务
  506. Db::rollback();
  507. // 记录错误信息
  508. $result['errors'][] = "Transaction failed: " . $e->getMessage();
  509. // 可以根据需要将 insert/update 摘要设置为失败
  510. $result['userUpdateSummary']['failed'] = count($usersToUpdate); // 假设更新失败
  511. $result['insertGongXianSummary']['failed'] = count($gongXianDataToInsert); // 假设插入失败
  512. $result['insertPvSummary']['failed'] = count($pvDataToInsert); // 假设插入失败
  513. }
  514. // --- 清理/最终结果赋值 (可选) ---
  515. // $result['gongXianDataOldList'] = $gongXianDataOldList; // 这些已合并到 ToInsert
  516. // $result['gongXianDataList'] = $gongXianDataList;
  517. // $result['pvDataOldList'] = $pvDataOldList;
  518. // $result['pvDataList'] = $pvDataList;
  519. return json($result);
  520. // // 计算总业绩
  521. // $totalPv = [];
  522. // foreach ($user_team_amount as $order) {
  523. // if (!isset($totalPv[$order['user_id']])) {
  524. // $totalPv[$order['user_id']] = 0;
  525. // }
  526. // switch ($order['money']) {
  527. // case 1180:
  528. // $totalPv[$order['user_id']] += 700;
  529. // break;
  530. // case 11800:
  531. // $totalPv[$order['user_id']] += 7000;
  532. // break;
  533. // case 10620:
  534. // $totalPv[$order['user_id']] += 6300;
  535. // break;
  536. // case 2360:
  537. // $totalPv[$order['user_id']] += 1400;
  538. // break;
  539. // case 9440:
  540. // $totalPv[$order['user_id']] += 5600;
  541. // break;
  542. // default:
  543. // if ($order['money'] == 2344.99) {
  544. // break;
  545. // }
  546. // $totalPv[$order['user_id']] += round($order['money'] * 0.7, 2);
  547. // break;
  548. // }
  549. // }
  550. // foreach ($totalPv as $uid => $pv) {
  551. // Db::name("user")->where('is_old', 1)->where("uid", $uid)->update(['pv' => $pv]);
  552. // }
  553. //
  554. // return;
  555. // /**
  556. // * 周金花200(13959100621)
  557. // * 黄金花200(18603401312)
  558. // * 徐立苹100(13521438652)
  559. // * 李素红200(13701061395)
  560. // * 周行体200(13231658486)
  561. // * 刘银霞100(13161909228)
  562. // * 李卫东100(13911601230)
  563. // * 金 波100(13801358713)
  564. // * 王 玲 150(15810064711)
  565. // * 侯玉兰150(15232797965)
  566. // * 吕丽娣100(15960349667)
  567. // * 张传莲100(15332507711)
  568. // * 刘春梅100(18760167163)
  569. // * 付天如100(18863873000)
  570. // * 付绍先100(15324059286)
  571. // * 黄桂林100(15960196876)
  572. // * 温 煌100(18350134089)
  573. // * 谭英先100(13978627072)
  574. // * 陈玉珍100(19858353660)
  575. // * 黄雪云100(18650055445)
  576. // * 黄 玲100(13877193411)
  577. // * 邱佳珍100(13960379098)
  578. // * 隋彩云100(13601071082)
  579. // */
  580. // $data = [
  581. // '13959100621' => 200,
  582. // '18603401312' => 200,
  583. // '13521438652' => 100,
  584. // '13701061395' => 200,
  585. // '13231658486' => 200,
  586. // '13161909228' => 100,
  587. // '13911601230' => 100,
  588. // '13801358713' => 100,
  589. // '15810064711' => 150,
  590. // '15232797965' => 150,
  591. // '15960349667' => 100,
  592. // '15332507711' => 100,
  593. // '18760167163' => 100,
  594. // '18863873000' => 100,
  595. // '15324059286' => 100,
  596. // '15960196876' => 100,
  597. // '18350134089' => 100,
  598. // '13978627072' => 100,
  599. // '19858353660' => 100,
  600. // '18650055445' => 100,
  601. // '13877193411' => 100,
  602. // '13960379098' => 100,
  603. // '13601071082' => 100,
  604. // ];
  605. // $result = Db::name("user")
  606. // ->whereIn("account", array_keys($data))
  607. // ->where('is_del', 0)
  608. // ->field('uid, brokerage_price, account, nickname')
  609. // ->select();
  610. // $res = [];
  611. // foreach ($result as $v) {
  612. // Db::name("user")->where("uid", $v['uid'])->inc("brokerage_price", $data[$v['account']])->save();
  613. // $this->bill_user_log111111($v['uid'], "佣金补贴", $data[$v['account']], "佣金补贴", 8);//股权分佣明细2.0系统
  614. // $res[] = [
  615. // 'uid' => $v['uid'],
  616. // 'account' => $v['account'],
  617. // 'brokerage_price_pre' => $v['brokerage_price'],
  618. // 'brokerage_price' => $data[$v['account']],
  619. // 'nickname' => $v['nickname']
  620. // ];
  621. // }
  622. // return json($res);
  623. }
  624. public function lst6()
  625. {
  626. $startTime = '2025-03-10';
  627. $endTime = '2025-03-30';
  628. // 查询测试人员账号信息
  629. //18973958920
  630. //15186694339
  631. //18833633835
  632. //19525470098
  633. //17756507016
  634. //18226705337
  635. $testAccount = ['18973958920', '15186694339', '18833633835', '19525470098', '17756507016', '18226705337'];
  636. $removeUserList = Db::name("user")
  637. ->whereIn('account', $testAccount)
  638. ->where("status", "<>", 0)
  639. ->where('is_del', '<>', 1)
  640. ->select()
  641. ->toArray();
  642. $removeUserIdList = array_column($removeUserList, 'uid');
  643. if (empty($startTime) || empty($endTime)) {
  644. $timeMap = $this->getTime('last_week');
  645. $startTime = $timeMap['startTime'] . ' 00:00:00';
  646. $endTime = $timeMap['endTime'] . ' 23:59:59';
  647. }
  648. // 定义分红金额
  649. $weekRecord = $this->getTeamPvByTime($startTime, $endTime, $removeUserIdList);
  650. // 分红金额 - 红包金额
  651. $redEnvelope = $this->getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList);
  652. $weekRecord -= $redEnvelope;
  653. if ($weekRecord <= 0) {
  654. return json('无效分红金额');
  655. }
  656. // $stock_comm = round($weekRecord * 0.05 ,2);
  657. $stock_comm = floor(($weekRecord * 0.05) * 100) / 100;
  658. //获取股权分红的人
  659. $GetAllUserPackNum = db::name("old_user_stock")->sum("pack");//计算所有用户的份数总和
  660. $stockuserdatas = db::name("old_user_stock")->select();//获取所有用户
  661. $salesArr = [];
  662. if (count($stockuserdatas) > 0) {
  663. // $one_pack_comm_data = round($stock_comm / $GetAllUserPackNum,2);//获取每份的单佣金
  664. $one_pack_comm_data = floor(($stock_comm / $GetAllUserPackNum) * 100) / 100;
  665. foreach ($stockuserdatas as &$v) {
  666. $salesArr[] = [
  667. 'stock_comm' => $stock_comm,
  668. 'GetAllUserPackNum' => $GetAllUserPackNum,
  669. 'uid' => $v['user_id'],
  670. 'pack' => $v['pack'],
  671. 'one_pack_comm_data' => $one_pack_comm_data,
  672. 'getcomm' => floor(($v['pack'] * $one_pack_comm_data) * 100) / 100
  673. ];
  674. $v['getcomm'] = floor(($v['pack'] * $one_pack_comm_data) * 100) / 100;
  675. $v['allgetcomm'] = $v['allgetcomm'] + $v['getcomm'];
  676. $v['update_time'] = time();
  677. $yj_90 = $v['getcomm'] * 0.9;
  678. $fg_10 = $v['getcomm'] * 0.1;
  679. // // 更新 user_stock 表中的记录
  680. $res = db::name("old_user_stock")->where("id", $v['id'])->update([
  681. 'getcomm' => $v['getcomm'],
  682. 'allgetcomm' => $v['allgetcomm'],
  683. 'update_time' => $v['update_time']
  684. ]);
  685. Db::name("user")->where("uid", $v['user_id'])->inc("brokerage_price", $yj_90)->save();
  686. $res1 = Db::name("user")->where("uid", $v['user_id'])->inc("total_amount_old", $yj_90)->save();
  687. $res2 = Db::name("user")->where("uid", $v['user_id'])->inc("amount_old", $yj_90)->save();
  688. $res3 = Db::name("user")->where("uid", $v['user_id'])->inc("fugou", $fg_10)->save();
  689. $res = true;
  690. if ($res) {
  691. $das = $this->change_user_log($v['user_id'], 'amount_old', 1, $yj_90, "member_award_stock", "股权分红入账" . "-" . $v['pack']);//释放佣金
  692. //入账星级分红记录表
  693. $week_data = [];
  694. $week_data['user_id'] = $v['user_id'];
  695. $week_data['user_star_id'] = 0;
  696. $week_data['award_num'] = 0;
  697. $week_data['award_num_sm'] = 0;
  698. $week_data['remark'] = "股权分红主动执行" . $yj_90;
  699. $week_data['week_record'] = $weekRecord;
  700. $week_data['all_amount'] = $stock_comm;
  701. $week_data['radio'] = 2;
  702. $week_data['owner_bill'] = 0; //总流水金额
  703. $week_data['my_bill'] = 0; //我的流水
  704. $week_data['create_time'] = time();
  705. Db::name("old_user_weekaward")->insert($week_data);
  706. $userdatassss = db::name("old_user_jbp")->where("id", $v['user_id'])->find();
  707. $datas_log = [
  708. 'note' => "名称:" . $userdatassss['nick_name'] . " 用户:" . $v['user_id'] . " 新增股权佣金:" . $yj_90,
  709. 'create_time' => date('Y-m-d H:i:s')
  710. ];
  711. $con_data = Db::name('test_log')->insert($datas_log); //数据存到2.0数据表中
  712. $this->bill_user_log111111($v['user_id'], "股权分佣", $yj_90, "股权明细入账", 13);//股权分佣明细2.0系统
  713. $this->fugou_user_log($v['user_id'], $fg_10, 16, 1, 1);//复购金明细入账
  714. }
  715. }
  716. }
  717. return json($salesArr);
  718. //股权分红 end
  719. }
  720. //添加复购金
  721. public function fugou_user_log($uid, $num, $order_id, $type_inc_des, $status = -1)
  722. {
  723. $fugou_data = Db::name('user')->where("uid", $uid)->find();
  724. $bill = [
  725. 'uid' => $uid,
  726. 'number' => $num,//数量
  727. 'status' => $status,//复购金状态1-有效 0-失效 -1待确认
  728. 'mark' => "复购金",//备注
  729. 'desc' => "10%作为复购金",//描述
  730. 'order_id' => $order_id,//订单id
  731. 'surplus' => 0,//剩余
  732. 'order_type' => 11,//关联订单ID
  733. 'type' => $type_inc_des,//复购金类型 :1赠送,2消耗
  734. 'settlement_time' => date('Y-m-d H:i:s'),//添加时间,
  735. 'addtime' => time(),
  736. ];
  737. Db::name('user_sign_fugou')->insert($bill);
  738. }
  739. //添加平台分佣2.0系统收益明细日志(养老金金额)
  740. public function bill_user_log111111($uid, $name, $num, $mark, $comm)
  741. {
  742. $con_data = Db::name('user')->where("uid", $uid)->find();
  743. //如果是会员专区就即刻到账
  744. // Db::name('user')->where("uid",$con_data['uid'])->update(['brokerage_price'=> $con_data['brokerage_price'] + $num]);
  745. $bill = [
  746. 'uid' => $uid,
  747. 'link_id' => 0,//关联订单id
  748. 'pm' => 1,//0:支出,1:获得
  749. 'title' => $name,//账单标题
  750. 'category' => 'now_money',//明细种类
  751. 'type' => 'commission',//明细类型
  752. 'number' => $num,//明细数字
  753. 'balance' => 0,//剩余
  754. 'mark' => $mark,//备注
  755. 'create_time' => date('Y-m-d H:i:s'),//添加时间
  756. 'status' => 1,//0待确定,1有效,-1无效
  757. 'commission_type' => $comm,//佣金类型 1代理费 2 消费佣金 3直推奖√ 4辖区佣金\r\n5 养老金√ 6 广告费
  758. //7 跨店奖励√ 8平台奖励 9渠道商\r\n10 推荐创客收益√ 11分红奖金√ 12代理区域收益√ 13消费循环佣金
  759. //14-推荐代理收益√ 15邀请小区团长升级√ 16大v分享奖√ 17创客合伙人√ 18积分奖励√ 19创客补贴√’
  760. 'order_sn' => 0,//订单号
  761. 'tripartite' => 0,//
  762. 'type_shop' => 0,//0平台1多多进宝2唯品会3苏宁易购4网易考拉5淘宝客6京东联盟7饿了么8线上
  763. 'mer_id' => 0,//商户id
  764. 'source' => 0,//1线下 0线上
  765. 'order_type' => 1,//1自营 2 第三方 订单类型
  766. 'is_red_brokerage' => 0,//1红积分对冲佣金 0正常佣金
  767. 'gzc' => 3,//养老金是否已进入公证处log表0:未进入。1:已进入
  768. 'take_time' => '',//结算时间
  769. 'district_id' => '',//
  770. 'street_id' => '',//
  771. 'month' => '',//月份
  772. ];
  773. Db::name('user_bill')->insert($bill);
  774. }
  775. //发放佣金 示例: $this->change_user_log($v,'amount',1,$all_award,"member_award","星级分红入账"."-".$value['title']);//释放佣金
  776. function change_user_log($user_id, $type, $change_status, $money, $routine, $remark = "", $is_admin = 1, $appoint_money = 0)
  777. {
  778. $transition = [
  779. 'pv' => 1,
  780. "gb" => 2,
  781. "df" => 3,
  782. "vr" => 4,
  783. "bt" => 5,
  784. "withdraw_quota_old" => 6,//提现
  785. "unsettled_pension" => 7,
  786. "amount_old" => 8//发放佣金
  787. ];
  788. $routineInfo = Db::name("old_routine_log_of_key")->where("key", $routine)->find();
  789. if (empty($routineInfo)) {
  790. return false;
  791. }
  792. $key_id = isset($routineInfo['id']) ? $routineInfo['id'] : 0;
  793. if ($appoint_money > 0) {
  794. $alter_money = $appoint_money;
  795. } else {
  796. //再去查询变更前的 金额
  797. $alter_money = Db::name("user")->where('uid', $user_id)->value($type);
  798. }
  799. if ($change_status == 1) {
  800. //新增前
  801. $alter_money = $alter_money - $money;
  802. } else if ($change_status == 2) {
  803. //减少前
  804. $alter_money = $alter_money + $money;
  805. }
  806. if ($alter_money < 0) {
  807. $alter_money = 0;
  808. }
  809. $inser_data = [];
  810. $inser_data['user_id'] = $user_id;
  811. $inser_data['type'] = $transition[$type];
  812. $inser_data['change_status'] = $change_status;
  813. $inser_data['money'] = $money;
  814. $inser_data['routine_log_of_key_id'] = $key_id;
  815. $inser_data['remark'] = $remark;
  816. $inser_data['is_admin'] = $is_admin;
  817. $inser_data['create_time'] = time();
  818. $inser_data['alter_money'] = isset($alter_money) ? $alter_money : 0;
  819. Db::name("old_user_log")->insert($inser_data);
  820. }
  821. public function getTime($timePeriod)
  822. {
  823. // 定义时间区间
  824. $now = time();
  825. $startTime = '';
  826. $endTime = '';
  827. if ($timePeriod == 'last_week') {
  828. // 上周的时间区间
  829. $startTime = date('Y-m-d', strtotime('monday last week', $now)); // 上周星期一的开始时间
  830. $endTime = date('Y-m-d', strtotime('sunday last week', $now)); // 上周星期日的结束时间
  831. } elseif ($timePeriod == 'this_week') {
  832. // 这周的时间区间
  833. $startTime = date('Y-m-d', strtotime('monday this week', $now)); // 这周星期一的开始时间
  834. $endTime = date('Y-m-d', strtotime('sunday this week', $now)); // 这周星期日的结束时间
  835. }
  836. // return ['startTime' => '2025-03-10', 'endTime' => '2025-03-23'];
  837. return ['startTime' => $startTime, 'endTime' => $endTime];
  838. }
  839. public function getTeamPvByTime($startTime, $endTime, $removeUserIdList = [])
  840. {
  841. // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
  842. $orders = Db::name("store_order")
  843. ->where('mer_id', 496)
  844. ->whereNotIn('uid', $removeUserIdList)
  845. ->whereIn('status', [0, 1, 2, 3])
  846. ->whereIn("total_price", [1180, 11800, 10620, 2360, 9440])
  847. ->whereBetween("pay_time", [$startTime, $endTime])
  848. ->whereNotNull("pay_time") // 排除 pay_time 为 NULL 的订单
  849. ->select();
  850. // 计算总业绩
  851. $totalPv = 0;
  852. foreach ($orders as $order) {
  853. switch ($order['total_price']) {
  854. case 1180:
  855. $totalPv += 700;
  856. break;
  857. case 11800:
  858. $totalPv += 7000;
  859. break;
  860. case 10620:
  861. $totalPv += 6300;
  862. break;
  863. case 2360:
  864. $totalPv += 1400;
  865. break;
  866. case 9440:
  867. $totalPv += 5600;
  868. break;
  869. }
  870. }
  871. return $totalPv;
  872. }
  873. public function getRedEnvelopeByTime($startTime, $endTime, $removeUserIdList = [])
  874. {
  875. // 查询指定时间区间内的所有订单,并排除 pay_time 为 NULL 的订单
  876. $redEnvelopeList = Db::name("user_sign_hongbao")
  877. ->whereNotIn('uid', $removeUserIdList)
  878. ->where('status', 1)
  879. ->whereBetween("settlement_time", [$startTime, $endTime])
  880. ->select()
  881. ->toArray();
  882. return floor(array_sum(array_column($redEnvelopeList, 'number')) * 100) / 100;
  883. }
  884. }