Model_logic_whlabel.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * 协助处理库存相关的数据处理小工具类
  4. */
  5. class Model_logic_whlabel extends Lin_Model {
  6. function __construct(){
  7. parent::__construct();
  8. $this->load->_model('Model_typeclass','typeclass');
  9. $this->load->_model('Model_classid','classid');
  10. $this->load->_model('Model_logic_weight','logic_weight');
  11. }
  12. protected $pmList = [];//品名匹配的数据
  13. protected $pm = [];
  14. protected $weightList = [];//重量匹配的数据
  15. //转化数组中需要变动的参数
  16. /**
  17. * $list 要转化的数组
  18. * $condition 要处理的条件 $column 要转化的字段 $zhinfo 要转化字段的处理方法
  19. */
  20. public function dataTran($list,$condition){
  21. foreach($condition as $v){
  22. if($v == 'pm'){
  23. $this->pmData();
  24. }
  25. }
  26. foreach($list as $k=>$v){
  27. if($v == 'pm'){
  28. $list[$k]['pm'] = $this->getPm($v['features']);
  29. }
  30. if($v == 'weight'){
  31. $list[$k]['weight'] = $this->getPm($v['features']);
  32. }
  33. }
  34. return $list;
  35. }
  36. protected function pmData(){
  37. $typeclass = $this->typeclass->find_all();
  38. $t = [];
  39. foreach ($typeclass as $v)
  40. {
  41. $t[$v['id']] = $v;
  42. }
  43. $this->pmList = $t;
  44. $this->pm = $this->classid->sku();
  45. }
  46. protected function getPm($features){
  47. $t = $this->pmList;
  48. $pm = $this->pm;
  49. $features = explode('-',trim($features,'-'));
  50. foreach($features as $v)
  51. {
  52. $zh = explode('|',trim($t[$v]['zh'],'|'));
  53. $pm[$t[$v]['classid']] = $zh[0];
  54. }
  55. $zh = implode(" ",$pm);
  56. $zh = str_replace('自然色 ','',rtrim($zh,' '));
  57. $zh = str_replace(array(' ',' ',' ',' ',' ',' ',' '),' ',$zh);
  58. return $zh;
  59. }
  60. protected function getWeight($features){
  61. $features = explode("-",trim($features,"-"));
  62. $type = 0;
  63. if(in_array(126,$features)){
  64. $type = 126;
  65. }
  66. if(in_array(127,$features)){
  67. $type = 127;
  68. }
  69. if(in_array(128,$features)){
  70. $type = 128;
  71. }
  72. if(in_array(130,$features)){
  73. $type = 130;
  74. }
  75. return $this->logic_weight->getWeightByFeature($type,$features);
  76. }
  77. }