goodsModel.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. class flow_goodsClassModel extends flowModel
  3. {
  4. public $base;
  5. public function initModel()
  6. {
  7. $this->base = m('goods');
  8. }
  9. protected function flowchangedata(){
  10. $this->rs['typeid'] = $this->base->gettypename($this->rs['typeid']);
  11. }
  12. //导入数据的测试显示
  13. public function flowdaorutestdata()
  14. {
  15. return array(
  16. 'typeid' => '办公耗材/笔',
  17. 'name' => '红色粉笔',
  18. 'num' => 'WP-829',
  19. 'guige' => '红色',
  20. 'xinghao' => '5厘米',
  21. 'price' => '0.1',
  22. 'unit' => '盒',
  23. 'stockcs' => '20',
  24. );
  25. }
  26. public function flowxiangfields(&$fields)
  27. {
  28. $fields['stock'] = '总库存';
  29. $where = '';
  30. if(ISMORECOM){
  31. $comid = arrvalue($this->rs,'comid','0');
  32. $where = ' and `comid`='.$comid.'';
  33. }
  34. $kcrow = m('godepot')->getall('1=1'.$where.'','*','`sort`');
  35. foreach($kcrow as $k1=>$rs1){
  36. $fields['stock_'.$rs1['id'].''] = $rs1['depotname'];
  37. }
  38. return $fields;
  39. }
  40. //
  41. public function flowrsreplace($rs, $lx=0)
  42. {
  43. if(isset($rs['typeid']) && is_numeric($rs['typeid']))
  44. $rs['typeid'] = $this->base->gettypename($rs['typeid']);
  45. //详情页下显示对应仓库库存
  46. if($lx==1){
  47. $drows = $this->db->getall("SELECT `depotid`,sum(count)count FROM `[Q]goodss` where aid=".$rs['id']." and `status`=1 GROUP BY `depotid`");
  48. foreach($drows as $k1=>$rs1)$rs['stock_'.$rs1['depotid'].''] = $rs1['count'];
  49. }
  50. return $rs;
  51. }
  52. //导入之前
  53. public function flowdaorubefore($rows)
  54. {
  55. $inarr = array();
  56. $db = m('goods');
  57. $num = 'goodstype';
  58. if(ISMORECOM && $cnum=$this->adminmodel->getcompanynum())$num.='_'.$cnum.'';
  59. foreach($rows as $k=>$rs){
  60. $rs['typeid'] = $this->option->gettypeid($num,$rs['typeid']);
  61. //判断是否存在
  62. $odi = $db->existsgoods($rs);
  63. if($odi)continue;
  64. $rs['price'] = floatval($this->rock->repempt($rs['price'],'0')); //金额
  65. //$rs['stockcs'] = (int)$this->rock->repempt(arrvalue($rs,'stockcs','0')); //无用
  66. $inarr[] = $rs;
  67. }
  68. return $inarr;
  69. }
  70. //导入后处理(刷新库存)
  71. public function flowdaoruafter($ddoa=array())
  72. {
  73. //初始库存
  74. m('goods')->setstock();
  75. }
  76. //删除时
  77. protected function flowdeletebill($sm)
  78. {
  79. m('goodss')->delete('`aid`='.$this->id.'');
  80. m('goods')->setstock();
  81. }
  82. protected function flowbillwhere($uid, $lx)
  83. {
  84. $where = '';
  85. $typeid = $this->rock->post('typeid','0');
  86. if($typeid!='0'){
  87. $alltpeid = m('option')->getalldownid($typeid);
  88. $where .= ' and `typeid` in('.$alltpeid.')';
  89. }
  90. return array(
  91. 'where' => $where,
  92. 'order' => 'optdt desc',
  93. );
  94. }
  95. }
粤ICP备19079148号