仓库盘点功能-ThinkPHP_学习随笔

 1 public function check() {
 2     $db = M('Bookinfo');
 3     $region = I('post.region');
 4     $c = $db -> count();
 5     for ($i=1; $i < $c ; $i++) {
 6         $data[$i] = $db -> where(array('region' => $i)) -> field('amount')-> select();
 7         if (!empty($data[$i])) {
 8             foreach ($data[$i] as $key => $value) {
 9                 if (is_array($value)) {
10                     foreach ($value as $keys => $values) {
11                         $data_array[$i] = $data_array[$i] + $values;
12                     }
13                 }
14             }
15         } else {
16             break;
17         }
18     }
19     foreach ($data_array as $key => $value) {
20         $count = $count + $value;
21     }
22     $this -> assign('count', $count);
23     $this -> assign('check', $data_array);
24     $this -> display('check');
25 }
 1 public function count() {
 2     $arr = I('post.');
 3     foreach ($arr as $key => $value) {
 4         if ($key == "amount") {
 5             $amount = $arr[$key];
 6         } elseif ($key == "count") {
 7             $count = $arr[$key];
 8         }
 9     }
10     for ($i=0; $i < count($amount) ; $i++) { 
11         if ($amount[$i] - $count[$i] > 0) {
12             $result[$i] = '亏损';
13         } else {
14             $result[$i] = '盈余';
15         }
16     }
17     if (array_sum($amount) - array_sum($count) > 0) {
18         $res = "盘亏";
19     } else {
20         $res = "盘盈";
21     }
22     $this -> assign('result', $result);
23     $this -> assign('res', $res);
24     ManageController::check();
25     $this -> display('check');
26 }

function check 统计总数;

function count 生成结果;

posted @ 2017-03-08 20:45  张兆晨  阅读(427)  评论(0编辑  收藏  举报