Order.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. namespace Scm\Lib;
  3. use Dever;
  4. class Order
  5. {
  6. public function updateGoods($id, $name, $data)
  7. {
  8. $table = Dever::input('table');
  9. $goods = Dever::param('goods', $data);
  10. $cash = Dever::param('cash', $data);
  11. if ($table && $goods) {
  12. $temp = explode('-', $goods);
  13. $update = array();
  14. $update['where_id'] = $id;
  15. $update['goods_id'] = $temp[0];
  16. $update['sku_id'] = $temp[1];
  17. $batch = Dever::param('batch', $data);
  18. if (!$batch) {
  19. $update['batch'] = date('Ymd');
  20. }
  21. if (isset($temp[2]) && !$cash) {
  22. //$update['cash'] = $temp[2];
  23. }
  24. Dever::db($table)->update($update);
  25. Dever::config('base')->hook = false;
  26. }
  27. }
  28. public function updateOrderNum($id, $name, $data)
  29. {
  30. $table = Dever::input('table');
  31. $prefix = Dever::input('prefix');
  32. if ($table && $prefix) {
  33. $servicer_store_id = Dever::param('servicer_store_id', $data);
  34. if ($servicer_store_id) {
  35. $info = Dever::db('scm_servicer/store')->find($servicer_store_id);
  36. if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
  37. Dever::db($table)->delete($id);
  38. Dever::alert('仓库[' . $info['name'] . ']收货地址未填写');
  39. }
  40. }
  41. $seller_shop_id = Dever::param('seller_shop_id', $data);
  42. if ($seller_shop_id) {
  43. $info = Dever::db('scm_seller/shop')->find($seller_shop_id);
  44. if ($info && $info['type'] == 1 && (!$info['area'] || !$info['address'] || !$info['truename'] || !$info['tel'])) {
  45. Dever::db($table)->delete($id);
  46. Dever::alert('门店[' . $info['name'] . ']收货地址未填写');
  47. }
  48. }
  49. $update['order_num'] = $this->getOrderNum($table, $prefix);
  50. $update['where_id'] = $id;
  51. Dever::db($table)->update($update);
  52. Dever::config('base')->hook = false;
  53. }
  54. }
  55. # 生成订单号
  56. public function getOrderNum($table, $prefix = 'C')
  57. {
  58. $where['order_num'] = Dever::order($prefix);
  59. $state = Dever::db($table)->one($where);
  60. if (!$state) {
  61. return $where['order_num'];
  62. } else {
  63. return $this->getOrderNum($table);
  64. }
  65. }
  66. # 查看订单详情
  67. public function show($order_table)
  68. {
  69. $id = Dever::input('order_id');
  70. $order_db = Dever::db($order_table);
  71. $order = $order_db->one($id);
  72. $order['config'] = $order_db->config['set'];
  73. $content = array();
  74. if (isset($order['type'])) {
  75. $type = Dever::db($order_table . '_type')->one($order['type']);
  76. $content[0][] = array('订单类型', $type['name']);
  77. }
  78. $content[0][] = array('订单状态', Dever::status($order['config']['status'], $order['status']));
  79. $content[0][] = array('下单时间', date('Y-m-d H:i', $order['cdate']));
  80. $order['info'] && $content[0][] = array('订单备注', $order['info']);
  81. $content[1] = $content[2] = array();
  82. $role = $this->show_role(array
  83. (
  84. 'seller' => '经销商',
  85. 'seller_shop' => '门店',
  86. 'servicer' => '配送商',
  87. 'servicer_store' => '仓库',
  88. 'supplier' => '供应商',
  89. ), $order, $content[1]);
  90. $this->show_audit($order, $content[2]);
  91. $result = array();
  92. $result[$order['order_num']] = array
  93. (
  94. 'type' => 'info',
  95. 'content' => $content
  96. );
  97. $this->show_address($order, $role, $result);
  98. $audit = Dever::input('audit');
  99. if ($audit == 1) {
  100. $this->show_goods_audit($order, $order_table, $result);
  101. } else {
  102. $this->show_goods($order, $order_table, $result);
  103. }
  104. $head = array
  105. (
  106. 'name' => '基本信息',
  107. 'btn' => $this->show_button($order, $order_table),
  108. );
  109. $html = Dever::show($head, $result);
  110. return $html;
  111. }
  112. # 显示订单角色
  113. private function show_role($role, $order, &$data)
  114. {
  115. $result = array();
  116. foreach ($role as $k => $v) {
  117. $col = $k . '_id';
  118. if (isset($order[$col]) && $order[$col] > 0) {
  119. $project = $k;
  120. $name = 'info';
  121. if (strstr($k, '_')) {
  122. $temp = explode('_', $k);
  123. $project = $temp[0];
  124. $name = $temp[1];
  125. }
  126. $table = 'scm_' . $project . '/' . $name;
  127. $result[$k] = Dever::db($table)->one($order[$col]);
  128. if ($result[$k]) {
  129. $data[] = array($v, $result[$k]['name']);
  130. }
  131. }
  132. }
  133. return $result;
  134. }
  135. # 显示审核信息
  136. private function show_audit($order, &$data)
  137. {
  138. if (isset($order['audit_admin']) && $order['audit_admin']) {
  139. $admin = Dever::db('manage/admin')->find($order['audit_admin']);
  140. $data = array
  141. (
  142. array('审核人', $admin['username']),
  143. array('审核状态', Dever::status($order['config']['audit'], $order['audit'])),
  144. array('审核备注', $order['audit_desc']),
  145. );
  146. }
  147. }
  148. # 显示订单地址
  149. private function show_address($order, $role, &$result)
  150. {
  151. if (!$order['address']) {
  152. if (isset($role['servicer_store'])) {
  153. $address = $role['servicer_store'];
  154. }
  155. if (isset($role['seller_shop'])) {
  156. $address = $role['seller_shop'];
  157. }
  158. } else {
  159. $address = Dever::json_decode($order['address']);
  160. }
  161. if ($address) {
  162. $address['area'] = Dever::load('area/api')->string($address['area']);
  163. $result['收货信息'] = array
  164. (
  165. 'type' => 'info',
  166. 'content' => array
  167. (
  168. array
  169. (
  170. array('联系人', $address['truename']),
  171. array('联系电话', $address['tel']),
  172. array('收货地址', $address['area'] . ',' . $address['address']),
  173. ),
  174. ),
  175. );
  176. }
  177. }
  178. # 显示订单商品清单
  179. private function show_goods($order, $order_table, &$result)
  180. {
  181. $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
  182. if ($data) {
  183. $table['head'] = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '状态');
  184. $table['body'] = array();
  185. $total_price = $total_num = 0;
  186. $status = Dever::db($order_table . '_goods')->config['status'];
  187. foreach ($data as $k => $v) {
  188. $goods_info = Dever::load('scm_product/lib/info')->getBaseInfo($v['goods_id'], $v['sku_id'], $v['unit_id']);
  189. $status_name = Dever::status($status, $v['status']);
  190. $num = $v['num'];
  191. if ($v['status'] == 2 && $v['unit_id'] != $goods_info['base_unit_id']) {
  192. if (!isset($order['supplier_id'])) {
  193. $order['supplier_id'] = false;
  194. }
  195. $unit = Dever::load('scm/lib/unit')->convertBase($v['goods_id'], $v['sku_id'], $v['unit_id'], $v['num'], $v['cash'], 0, $order['supplier_id']);
  196. if ($unit) {
  197. $base_unit = Dever::db('scm/unit')->find($unit['unit_id']);
  198. $goods_info['unit'] .= ' => '.$unit['num'].''.$base_unit['name'].'';
  199. $num = $unit['num'];
  200. }
  201. }
  202. $cash = Dever::number($v['cash'] * $v['num']);
  203. $detail = array
  204. (
  205. $goods_info['code'],
  206. $goods_info['aname'],
  207. );
  208. if (isset($v['batch'])) {
  209. $detail[] = $v['batch'] . (isset($v['sdate']) && $v['sdate'] ? '[' . date('Y-m-d', $v['sdate']) . '生产]' : '');
  210. } else {
  211. unset($table['head'][3]);
  212. }
  213. $detail[] = $v['cash'];
  214. $detail[] = $v['num'] . $goods_info['unit'];
  215. $detail[] = $cash;
  216. $detail[] = $status_name;
  217. if ($goods_info['goods']) {
  218. $detail['goods'] = $goods_info['goods'];
  219. }
  220. $table['body'][] = $detail;
  221. $total_price += $cash;
  222. $total_num += $num;
  223. }
  224. $result['商品清单'] = array
  225. (
  226. 'type' => 'table',
  227. 'head' => array('name' => '', 'btn' => ''),
  228. 'content' => $table,
  229. 'total' => '合计金额:' . Dever::number($total_price) . ',合计数量:' . $total_num
  230. );
  231. }
  232. }
  233. # 显示按钮
  234. private function show_button($order, $order_table)
  235. {
  236. $button = array();
  237. if ($order['status'] == 1) {
  238. list($project, $table) = explode('/', $order_table);
  239. $url = Dever::url('project/database/update?project='.$project.'&table='.$table.'&where_id='.$order['id'].'&col=audit,audit_desc', 'manage');
  240. $button[] = array
  241. (
  242. 'type' => 'edit',
  243. 'link' => $url,
  244. 'name' => '审核',
  245. );
  246. }
  247. return $button;
  248. }
  249. private function show_goods_audit($order, $order_table, &$result)
  250. {
  251. $order['type'] = 1;
  252. $data = Dever::db($order_table . '_goods')->select(array('order_id' => $order['id']));
  253. print_r($order);die;
  254. $seller = Dever::db('scm_seller/info')->find($order['seller_shop_id']);
  255. $seller = Dever::db('scm_seller/shop')->find($order['seller_shop_id']);
  256. list($assign, $source) = Dever::load('scm/lib/assign')->get($goods, $info, $shop, true);
  257. if ($info) {
  258. $head = array('商品编码', '商品名称', '批次', '单价', '数量', '总价', '供货商');
  259. $body = array();
  260. $i = 0;
  261. if ($data) {
  262. foreach ($assign as $k => $v) {
  263. foreach ($v as $v1) {
  264. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v1['goods_id'], $v1['sku_id']);
  265. if (isset($goods_info['sku'])) {
  266. $sku = '[' . $goods_info['sku']['string'] . ']';
  267. } else {
  268. $sku = '';
  269. }
  270. $d = array
  271. (
  272. $i+1,
  273. $goods_info['code'],
  274. $goods_info['name'] . $sku,
  275. $this->getSelect($source, $v1['source_id'], $v1['order_goods_id']),
  276. $v1['num'],
  277. $goods_info['unit'],
  278. $v1['p_price'] * $v1['num'],
  279. );
  280. $body[] = $d;
  281. $i++;
  282. }
  283. }
  284. }
  285. if ($goods) {
  286. foreach ($goods as $k => $v) {
  287. $goods_info = Dever::load('goods/lib/info')->getInfoBySku($v['goods_id'], $v['sku_id']);
  288. if (isset($goods_info['sku'])) {
  289. $sku = '[' . $goods_info['sku']['string'] . ']';
  290. } else {
  291. $sku = '';
  292. }
  293. $d = array
  294. (
  295. $i+1,
  296. $goods_info['code'],
  297. $goods_info['name'] . $sku,
  298. $this->getSelect($source, false, $v['id']),
  299. $v['num'],
  300. $goods_info['unit'],
  301. $v['p_price'] * $v['num'],
  302. );
  303. $body[] = $d;
  304. $i++;
  305. }
  306. }
  307. $btn = array();
  308. $btn[] = array(
  309. 'type' => 'click',
  310. 'content' => 'setAudit()',
  311. 'name' => '全部调整<script>function setAudit(){layer.confirm(\'确定进行此项操作吗?\', function(){var audit = $(\'.audit_set\').val();$(\'.audit\').each(function(){$(this).val(audit);layui.form.render();layer.closeAll()})})}</script>'
  312. );
  313. $result['商品拆单'] = array
  314. (
  315. 'type' => 'table',
  316. 'head' => array('name' => '供货商:' . $this->getSelect($source, false, false), 'btn' => $btn),
  317. 'content' => array
  318. (
  319. 'head' => $head,
  320. 'body' => $body,
  321. )
  322. );
  323. $url = Dever::url('lib/buy.audit_set_commit?json=1&order_id=' . $info['id'], 'mshop');
  324. $result['审核结果'] = array
  325. (
  326. 'type' => 'html',
  327. 'content' => '<script>function saveAudit(){var goods = [];var audit = 1; var audit_text = $(".update_audit_text").val();$(".update_audit").each(function(){if ($(this).get(0).checked){audit = $(this).val()}});$(\'.audit\').each(function(){var v = $(this).val();var id = $(this).attr("id");goods.push(v + "_" + id);});layer.confirm(\'确定进行此项操作吗?\', function(){layui.form.render();var send = {};send.goods = goods.join(",");send.audit = audit;send.audit_text = audit_text;console.info(send);$.post("'.$url.'", send, function(t){t = JSON.parse(t);showYes(t)})})}</script><style>.layui-form-radio{padding-right: 0px;margin: 0px 0px 0 0;margin-left:40px}</style><div class="layui-form-item show_input"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核状态</label><div style="display:inline" class="am-btn-group"><input update_type="checked" class="checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="2" checked="" show_id="audit" autocomplete="off" id="form-validation-field-1"> 审核通过 &nbsp;&nbsp;<input update_type="checked" class="autoload checkbox-checkall-0_update_audit update_audit update_value validate[required]" type="radio" name="update_audit[]" value="3" autocomplete="off" id="form-validation-field-0"> 审核未通过 &nbsp;&nbsp;</div></div></div></div><div class="layui-form-item" style="display: block;"><div classs="layui-col-lg6"><div><label style="font-size:14px;font-weight:bold;" class="">审核备注</label></div><div><textarea style="height:100px;" update_type="value" class="update_value update_audit_text form-control layui-input validate[required]" name="update_desc"></textarea></div></div></div> <div style="text-align:left" class="layui-layer-btn layui-layer-btn-"><a class="layui-btn layui-btn-primary" onclick="saveAudit()">保存</a><a class="layui-layer-btn1" style="display:none">取消</a></div>',
  328. );
  329. }
  330. }
  331. }