Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProductSpecValueHandle.php 4.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 陈风任 <491085389@qq.com>
  11. * Date: 2019-7-9
  12. */
  13. namespace app\admin\model;
  14. use think\Model;
  15. use think\Config;
  16. use think\Db;
  17. /**
  18. * 商品规格价格预处理模型
  19. */
  20. class ProductSpecValueHandle extends Model
  21. {
  22. //初始化
  23. protected function initialize()
  24. {
  25. // 需要调用`Model`的`initialize`方法
  26. parent::initialize();
  27. }
  28. public function editProductSpecPrice($post = [])
  29. {
  30. $aid = !empty($post['aid']) ? $post['aid'] : session('handleAID');
  31. if (!empty($aid) && !empty($post['spec_price']) && !empty($post['spec_stock'])) {
  32. // 产品规格价格及规格库存
  33. $time = getTime();
  34. $saveAll = $insertAll = [];
  35. $keys = rand(1, 9);
  36. foreach ($post['spec_price'] as $kkk => $vvv) {
  37. if (!empty($post['value_ids'][$kkk]['value_id'])) {
  38. $saveAll[] = [
  39. 'value_id' => intval($post['value_ids'][$kkk]['value_id']),
  40. 'aid' => $aid,
  41. 'spec_value_id' => $kkk,
  42. 'spec_price' => !empty($vvv['users_price']) ? $vvv['users_price'] : 0,
  43. 'spec_crossed_price' => !empty($post['spec_crossed_price'][$kkk]['crossed_price']) ? $post['spec_crossed_price'][$kkk]['crossed_price'] : 0,
  44. 'spec_stock' => !empty($post['spec_stock'][$kkk]['stock_count']) ? $post['spec_stock'][$kkk]['stock_count'] : 0,
  45. 'spec_sales_num'=> !empty($post['spec_sales'][$kkk]['spec_sales_num']) ? $post['spec_sales'][$kkk]['spec_sales_num'] : 0,
  46. 'update_time' => $time,
  47. ];
  48. } else if (!empty($vvv['users_price'])) {
  49. $keys++;
  50. $insertAll[] = [
  51. 'value_id' => date('His') . rand(10, 99) . $keys,
  52. 'aid' => $aid,
  53. 'spec_value_id' => $kkk,
  54. 'spec_price' => !empty($vvv['users_price']) ? $vvv['users_price'] : 0,
  55. 'spec_crossed_price' => !empty($post['spec_crossed_price'][$kkk]['crossed_price']) ? $post['spec_crossed_price'][$kkk]['crossed_price'] : 0,
  56. 'spec_stock' => !empty($post['spec_stock'][$kkk]['stock_count']) ? $post['spec_stock'][$kkk]['stock_count'] : 0,
  57. 'spec_sales_num'=> !empty($post['spec_sales'][$kkk]['spec_sales_num']) ? $post['spec_sales'][$kkk]['spec_sales_num'] : 0,
  58. 'add_time' => $time,
  59. 'update_time' => $time,
  60. ];
  61. }
  62. }
  63. if (!empty($saveAll)) $this->saveAll($saveAll);
  64. if (!empty($insertAll)) Db::name('product_spec_value_handle')->insertAll($insertAll);
  65. // 查询商品的规格信息
  66. $where = [
  67. 'aid' => $aid,
  68. 'spec_is_select' => 1,
  69. ];
  70. $field = 'spec_mark_id, spec_value_id';
  71. $order = 'spec_value_id asc, spec_id asc';
  72. $data = Db::name('product_spec_data_handle')->field($field)->where($where)->order($order)->select();
  73. // 处理规格数组
  74. $resultArray = [];
  75. if (!empty($data)) {
  76. foreach ($data as $key => $value) {
  77. $resultArray[$value['spec_mark_id']][] = $value['spec_value_id'];
  78. }
  79. }
  80. return [
  81. 'aid' => $aid,
  82. 'resultArray' => $resultArray,
  83. ];
  84. }
  85. return false;
  86. }
  87. }