Consult.php 123 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\ActionLog;
  4. use app\admin\model\ProcessOrder;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\Validate;
  8. //咨询单
  9. class Consult extends Base
  10. {
  11. public $noble=[];
  12. public function __construct(App $app)
  13. {
  14. parent::__construct($app);
  15. $this->noble =\think\facade\Config::get("noble");
  16. }
  17. public function conlist(){
  18. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  19. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  20. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  21. $infoNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  22. if ($infoNo !== "") {
  23. $where[] = ['a.infoNo','like','%'.$infoNo.'%'];
  24. }
  25. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  26. if ($salesman !== "") {
  27. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  28. $where[]= ["b.salesman",'like',"%$salesman%"];
  29. }
  30. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  31. if ($cpName !== "") {
  32. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  33. $where[]= ["a.good_Name",'like',"%$cpName%"];
  34. }
  35. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  36. if ($khNo !== "") {
  37. // $where['khNo'] = $khNo;
  38. $where[]= ["b.khNo",'like',"%$khNo%"];
  39. }
  40. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !== "" ? trim($this->post['companyNo']) : "";
  41. if ($companyNo !== "") {
  42. // $where['khNo'] = $khNo;
  43. $where[]= ["b.companyNo",'like',"%$companyNo%"];
  44. }
  45. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  46. if ($start !="") {
  47. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  48. $where[]= ["a.addtime",'>=',$start];
  49. }
  50. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  51. if($end !=""){
  52. $where[]= ["a.addtime",'<=',$end];
  53. }
  54. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  55. if ($status !== "") {
  56. $where[]= ["a.status",'=',$status];
  57. }
  58. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  59. if ($company_name !== "") $where[] = ["b.createrid", 'in', get_company_item_user_by_name($company_name)];
  60. $role=$this->checkRole();
  61. if(!empty($role['write'])){
  62. $where[]=["b.createrid","in",$role['write']];
  63. }
  64. // if(!empty($role['platform']) ){
  65. // $where[]=["b.platform_code","in",$role['platform']];
  66. // }
  67. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  68. ->count();
  69. $total = ceil($count / $size);
  70. $page = $page >= $total ? $total : $page;
  71. $list = Db::name('consult_info')
  72. ->alias("a")
  73. ->leftJoin("consult_order b", "a.zxNo=b.zxNo")
  74. ->leftJoin("depart_user u", "u.uid=b.createrid AND u.is_del=0")
  75. ->where($where)
  76. ->page($page, $size)
  77. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart,u.itemid")
  78. ->order("a.id desc")
  79. ->cursor();
  80. $data=[];
  81. foreach ($list as $value){
  82. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  83. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  84. true):[];
  85. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  86. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  87. $value['khname']="";
  88. if($value['khNo']!==""){
  89. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  90. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  91. }
  92. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  93. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  94. $data[]=$value;
  95. }
  96. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  97. }
  98. public function info(){
  99. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  100. if($id==""){
  101. return error_show(1002,"咨询单编号不能为空");
  102. }
  103. $fo = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  104. $in= isset($fo['cat_id']) && $fo['cat_id'] !=0 ? made($fo['cat_id']):[];
  105. $fo['can']=$in;
  106. if(empty($fo)){
  107. return error_show(1002,"未找到咨询单编号");
  108. }else{
  109. return app_show(0,"获取成功",$fo);
  110. }
  111. }
  112. public function del(){
  113. $id = isset($this->post['id']) && $this->post['id'] !=="" ? intval($this->post['id']) : "";
  114. $de = Db::name('consult')->where(['id'=>$id,'is_del'=>0])->find();
  115. if($de==false){
  116. return error_show(1002,'咨询单信息未找到');
  117. }
  118. $dell= Db::name('consult')->update(['id'=>$id,'is_del'=>1,'updatetime'=>date("Y-m-d H:i:s")]);
  119. if($dell){
  120. return error_show(0,"删除成功");
  121. }else
  122. return error_show(1002,"删除失败");
  123. }
  124. public function create(){
  125. $is_project= isset($this->post['is_project']) && $this->post['is_project'] !=="" ? intval($this->post['is_project']) : "";
  126. if($is_project===""){
  127. return error_show(1002,"参数is_project不能为空");
  128. }
  129. if($is_project==1){
  130. $projectNo= isset($this->post['projectNo']) && $this->post['projectNo'] !=="" ? trim($this->post['projectNo']) : "";
  131. if($projectNo===""){
  132. return error_show(1002,"参数projectNo不能为空");
  133. }
  134. }
  135. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !=="" ? trim($this->post['khNo']) : "";
  136. if($khNo===""){
  137. return error_show(1002,"参数khNo不能为空");
  138. }
  139. $companyNo = isset($this->post['companyNo']) && $this->post['companyNo'] !=="" ? trim($this->post['companyNo']) : "";
  140. if($companyNo===""){
  141. return error_show(1002,"参数companyNo不能为空");
  142. }
  143. $endtime = isset($this->post['endtime']) && $this->post['endtime'] !=="" ? $this->post['endtime'] : "";
  144. if($endtime===""){
  145. return error_show(1002,"参数endtime不能为空");
  146. }
  147. $platform_code = isset($this->post['platform_code']) && $this->post['platform_code'] !=="" ? trim($this->post['platform_code']) :
  148. "";
  149. if($platform_code===""){
  150. return error_show(1002,"参数platform_code不能为空");
  151. }
  152. $ladder = isset($this->post['ladder'])&&!empty($this->post['ladder']) ? $this->post['ladder']:"";
  153. if($ladder==""){
  154. return error_show(1005,"参数ladder不能为空");
  155. }
  156. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  157. if($token==''){
  158. return error_show(105,"参数token不能为空");
  159. }
  160. $user =GetUserInfo($token);
  161. if(empty($user)||$user['code']!=0){
  162. return error_show(102,"用户数据不存在");
  163. }
  164. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  165. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  166. $depart= Db::name("depart_user")->where(["uid"=>$createrid,"status"=>1,"is_del"=>0])->find();
  167. $zxNo=makeNo("ZX");
  168. Db::startTrans();
  169. try{
  170. $data=[
  171. "zxNo"=>$zxNo,
  172. "createrid"=>$createrid,
  173. "creater"=>$creater,
  174. "is_project"=>$is_project,
  175. "projectNo"=>isset($projectNo) ? $projectNo:"",
  176. "khNo"=>$khNo,
  177. "companyNo"=>$companyNo,
  178. "endtime"=>$endtime,
  179. "salesman"=>$creater,
  180. "platform_code"=>$platform_code,
  181. "saleid"=>$createrid,
  182. "depart"=>isset($depart['itemid'])?$depart['itemid']:0,
  183. "status"=>0,
  184. "is_del"=>0,
  185. "addtime"=>date("Y-m-d H:i:s"),
  186. "updatetime"=>date("Y-m-d H:i:s"),
  187. ];
  188. $zx = Db::name("consult_order")->insert($data);
  189. if($zx){
  190. //判断是否是项目,且该项目是否存在台账记录中
  191. if($is_project==1) $stand_exists=Db::name('standing_book')->field('id')->where('projectNo',$projectNo)->find();
  192. foreach ($ladder as $value){
  193. $infoNo=makeNo("IF");
  194. $specinfo=[];
  195. if(isset($value['specinfo']) &&!empty($value['specinfo'])){
  196. foreach ($value["specinfo"] as $v){
  197. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  198. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  199. $v['spec_name']=isset($spec['spec_name'])? $spec['spec_name']:"";
  200. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"" ;
  201. $specinfo[]=$v;
  202. }
  203. }
  204. $info=[
  205. "infoNo"=>$infoNo,
  206. "zxNo"=>$zxNo,
  207. "spuCode"=>"",
  208. "good_name"=>$value['good_name'],
  209. "good_img"=>$value['good_img'],
  210. "cat_id"=>$value['cat_id'],
  211. "unit"=>$value['unit'],
  212. "brand_id"=>$value['brand_id'],
  213. "arrival_time"=>$value['arrival_time'],
  214. "specinfo"=>empty($specinfo)?"" : json_encode($specinfo),
  215. "cost_desc" => isset($value['cost_desc']) ? $value['cost_desc'] : '',
  216. "is_addrs"=>$value['is_addrs'],
  217. "is_custom"=>$value['is_custom'],
  218. "metal_id"=>$value['metal_id'],
  219. "config"=>isset($value['config'])?$value['config']:"",
  220. "other_config"=>isset($value['other_config'])?$value['other_config']:"",
  221. "specs_weight"=>isset($value['specs_weight'])?$value['specs_weight']:"0",
  222. "gold_price"=>isset($value['gold_price'])?$value['gold_price']:"0",
  223. "is_gold_price"=>isset($value['is_gold_price'])?$value['is_gold_price']:"0",
  224. "total_weight"=>isset($value['total_weight'])?$value['total_weight']:"0",
  225. "budget_price"=>$value['budget_price'],
  226. "num"=>$value['num'],
  227. "pgNo"=>isset($value['pgNo'])&&$value['pgNo']!==""?trim($value['pgNo']):"",
  228. "use_desc"=>$value['use_desc'],
  229. "remark"=>$value['remark'],
  230. "status"=>1,
  231. "is_del"=>0,
  232. "addtime"=>date("Y-m-d H:i:s"),
  233. "updatetime"=>date("Y-m-d H:i:s"),
  234. 'enclosure_file'=>isset($value['enclosure_file'])?$value['enclosure_file']:'',
  235. ];
  236. $up = Db::name("consult_info")->insert($info);
  237. if(!$up){
  238. Db::rollback();
  239. return error_show(1004,'添加失败');
  240. }else{
  241. //修改状态,添加待办
  242. ActionLog::logAdd($this->post['token'], [
  243. "order_code" => $infoNo,//咨询单详情编号
  244. "status" => 1,//这里的status是之前的值
  245. "action_remark" => '',//备注
  246. "action_type" => "create"//新建create,编辑edit,更改状态status
  247. ], "ZXD", 1, $info);
  248. // ProcessOrder::AddProcess($this->post['token'], [
  249. // "order_type" => 'ZXD',
  250. // "order_code" => $infoNo,//咨询单详情编号
  251. // "order_id" => 0,
  252. // "order_status" => 1
  253. // ]);
  254. //如果存在该项目编码,更新对应的第一个竞价单编码,其他竞价单编码新增(带着项目编码)
  255. if (isset($stand_exists)) {
  256. Db::name('standing_book')
  257. ->where('id', $stand_exists['id'])
  258. ->update([
  259. 'infoNo' => $infoNo,
  260. 'updatetime' => date('Y-m-d H:i:s')
  261. ]);
  262. unset($stand_exists);//后面的竞价单编码不用更新,都是新增
  263. } else {
  264. //添加台账信息
  265. Db::name('standing_book')
  266. ->insert([
  267. 'standBookNo' => makeNo("IO"),
  268. 'projectNo' => isset($projectNo) ? $projectNo : '',
  269. 'infoNo' => $infoNo,
  270. 'addtime' => date('Y-m-d H:i:s'),
  271. 'updatetime' => date('Y-m-d H:i:s')
  272. ]);
  273. }
  274. }
  275. }
  276. Db::commit();
  277. return app_show(0,"新建成功",["zxNo"=>$zxNo]);
  278. }else{
  279. Db::rollback();
  280. return error_show(1004,"新建失败");
  281. }
  282. }catch (\Exception $e){
  283. Db::rollback();
  284. return error_show(1003,$e->getMessage());
  285. }
  286. }
  287. public function zxinfo(){
  288. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  289. if($infoNo==""){
  290. return error_show(1004,"参数infoNo不能为空");
  291. }
  292. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  293. if($zxinfo==false){
  294. return error_show(1004,"未找到信息数据");
  295. }
  296. $zxorder = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  297. if($zxorder==false){
  298. return error_show(1004,"未找到咨询信息数据");
  299. }
  300. $cat =Db::name("cat")->where(["id"=>$zxinfo['cat_id']])->find();
  301. $budget = isset($cat['order_rate']) ? $cat['order_rate']:0;
  302. $zxinfo['can']= isset($zxinfo['cat_id']) && $zxinfo['cat_id'] !=0 ? made($zxinfo['cat_id'],[]):[];
  303. $zxinfo['khname']="";
  304. $zxinfo['original_price']=sprintf("%.2f",$zxinfo['budget_price']* (1 -$budget/100));
  305. $zxinfo['khNo']="";
  306. $zxinfo['brand_id']=$zxinfo['brand_id']==0 ?"":$zxinfo['brand_id'];
  307. $zxinfo['brand']="";
  308. $zxinfo['companyNo']=isset($zxorder['companyNo'])?$zxorder['companyNo']:"";
  309. $zxinfo['projectNo']=isset($zxorder['projectNo'])?$zxorder['projectNo']:"";
  310. $zxinfo['is_project']=isset($zxorder['is_project'])?$zxorder['is_project']:"";
  311. $zxinfo['company']="";
  312. $zxinfo['endtime']=isset($zxorder['endtime'])?$zxorder['endtime']:"";
  313. $zxinfo['platform_code'] =isset($zxorder['platform_code'])?$zxorder['platform_code']:"";
  314. $zxinfo['salesman'] =isset($zxorder['salesman'])?$zxorder['salesman']:"";
  315. $zxinfo['saleid'] =isset($zxorder['saleid'])?$zxorder['saleid']:"";
  316. $zxinfo['depart'] =isset($zxorder['depart'])?$zxorder['depart']:"";
  317. $zxinfo['project_name']="";
  318. $zxinfo['budget_total']="";
  319. $zxinfo['departinfo']=[];
  320. $zxinfo['unit_name']="";
  321. $zxinfo['metal_name']=isset($zxinfo['metal_id'])&& $zxinfo['metal_id']!=0?$this->noble[$zxinfo['metal_id']]:"";
  322. $zxinfo['specinfo']=json_decode($zxinfo['specinfo'],true);
  323. if($zxorder['khNo']!==""){
  324. $kh=Db::name("customer_info")->where(['companyNo'=>$zxorder['khNo']])->find();
  325. $zxinfo['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  326. $zxinfo['khNo']= $zxorder['khNo'];
  327. }
  328. if($zxinfo['unit']!==""){
  329. $unit=Db::name("unit")->where(['id'=>$zxinfo['unit']])->find();
  330. $zxinfo['unit_name']= isset($unit['unit'])?$unit['unit']:"";
  331. }
  332. if($zxinfo['brand_id']!==""){
  333. $unit=Db::name("brand")->where(['id'=>$zxinfo['brand_id']])->find();
  334. $zxinfo['brand']= isset($unit['brand_name'])?$unit['brand_name']:"";
  335. }
  336. if($zxorder['companyNo']!==""){
  337. $kh=Db::name("business")->where(['companyNo'=>$zxorder['companyNo']])->find();
  338. $zxinfo['company']= isset($kh['company'])?$kh['company']:"";
  339. }
  340. if($zxorder['is_project']==1 && $zxorder['projectNo']!==""){
  341. $project = Db::name("project")->where(["projectNo"=>$zxorder['projectNo'],"is_del"=>0])->find();
  342. $zxinfo['project_name']=isset($project['project_name'])?$project['project_name']:"";
  343. $zxinfo['budget_total']=isset($project['budget_total'])?$project['budget_total']:"";
  344. $zxinfo['project_use_desc']=isset($project['use_desc'])?$project['use_desc']:"";
  345. $projectinfo = Db::name("project_info")->where(["pgNo"=>$zxinfo['pgNo']])->find();
  346. $zxinfo['pgNo'] = isset($projectinfo['pgNo']) ? $projectinfo['pgNo']:"";
  347. }
  348. if($zxorder['depart']>0){
  349. $zxinfo['departinfo']=GetPart($zxorder['depart']);
  350. }
  351. if($zxorder['platform_code']>0){
  352. $palt=Db::name("platform")->where(["id"=>$zxorder['platform_code']])->find();
  353. $zxinfo['platform_name']=isset($palt['platform_name'])?$palt['platform_name']:"";
  354. }
  355. return app_show(0,"获取成功",$zxinfo);
  356. }
  357. public function zxedit(){
  358. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  359. if($infoNo==""){
  360. return error_show(1004,"参数infoNo不能为空");
  361. }
  362. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  363. if($zxinfo==false){
  364. return error_show(1004,"未找到信息数据");
  365. }
  366. $enclosure_file =isset($this->post['enclosure_file'])&&$this->post['enclosure_file']!=""?trim($this->post['enclosure_file']):$zxinfo['enclosure_file'];
  367. $good_name= isset($this->post['good_name'])&&$this->post['good_name']!=""?trim($this->post['good_name']):"";
  368. if($good_name==""){
  369. return error_show(1003,"参数good_name不能为空");
  370. }
  371. $good_img= isset($this->post['good_img'])&&$this->post['good_img']!=""?trim($this->post['good_img']):"";
  372. if($good_img==""){
  373. return error_show(1003,"参数good_img不能为空");
  374. }
  375. $cat_id= isset($this->post['cat_id'])&&$this->post['cat_id']!=""?intval($this->post['cat_id']):"";
  376. if($cat_id==""){
  377. return error_show(1003,"参数cat_id不能为空");
  378. }
  379. $unit= isset($this->post['unit'])&&$this->post['unit']!=""?trim($this->post['unit']):"";
  380. if($unit==""){
  381. return error_show(1003,"参数unit不能为空");
  382. }
  383. $brand_id= isset($this->post['brand_id'])&&$this->post['brand_id']!==""?intval($this->post['brand_id']):"0";
  384. $arrival_time= isset($this->post['arrival_time'])&&$this->post['arrival_time']!=""?$this->post['arrival_time']:"";
  385. if($arrival_time==""){
  386. return error_show(1003,"参数arrival_time不能为空");
  387. }
  388. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  389. if($specin==""){
  390. return error_show(1003,"参数specinfo不能为空");
  391. }
  392. $cost_desc= isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""?trim($this->post['cost_desc']):"";
  393. // if($cost_desc==""){
  394. // return error_show(1003,"参数cost_desc不能为空");
  395. // }
  396. $is_addrs= isset($this->post['is_addrs'])&&$this->post['is_addrs']!==""?intval($this->post['is_addrs']):"";
  397. if($is_addrs===""){
  398. return error_show(1003,"参数is_addrs不能为空");
  399. }
  400. $is_custom= isset($this->post['is_custom'])&&$this->post['is_custom']!==""?trim($this->post['is_custom']):"";
  401. if($is_custom===""){
  402. return error_show(1003,"参数is_custom不能为空");
  403. }
  404. $metal_id= isset($this->post['metal_id'])&&$this->post['metal_id']!==""?intval($this->post['metal_id']):"";
  405. if($metal_id===""){
  406. return error_show(1003,"参数metal_id不能为空");
  407. }
  408. $config = isset($this->post['config'])&& $this->post['config']!=""?trim($this->post['config']):"";
  409. $other_config = isset($this->post['other_config'])&& $this->post['other_config']!=""?trim($this->post['other_config']):"";
  410. $specs_weight = isset($this->post['specs_weight'])&& $this->post['specs_weight']!==""?floatval($this->post['specs_weight']):"";
  411. $gold_price = isset($this->post['gold_price'])&& $this->post['gold_price']!==""?floatval($this->post['gold_price']):"";
  412. $is_gold_price = isset($this->post['is_gold_price'])&& $this->post['is_gold_price']!==""?intval($this->post['is_gold_price']):"0";
  413. $budget_price = isset($this->post['budget_price'])&& $this->post['budget_price']!==""?floatval($this->post['budget_price']):"";
  414. $total_weight = isset($this->post['total_weight'])&& $this->post['total_weight']!==""?floatval($this->post['total_weight']):"";
  415. $num = isset($this->post['num'])&& $this->post['num']!==""?intval($this->post['num']):"";
  416. if($num===""){
  417. return error_show(1003,"参数num不能为空");
  418. }
  419. if($budget_price===""){
  420. return error_show(1003,"参数budget_price不能为空");
  421. }
  422. $pgNo = isset($this->post['pgNo'])&& $this->post['pgNo']!="" ? trim($this->post['pgNo']):"";
  423. $use_desc = isset($this->post['use_desc'])&& $this->post['use_desc']!="" ? trim($this->post['use_desc']):"";
  424. if($use_desc==""){
  425. return error_show(1003,"参数use_desc不能为空");
  426. }
  427. $remark = isset($this->post['remark'])&& $this->post['remark']!="" ? trim($this->post['remark']):"";
  428. if($remark==""){
  429. return error_show(1003,"参数remark不能为空");
  430. }
  431. $endtime = isset($this->post['endtime'])&& $this->post['endtime']!="" ? trim($this->post['endtime']):"";
  432. if($endtime==""){
  433. return error_show(1003,"参数endtime不能为空");
  434. }
  435. if($metal_id!=0){
  436. if($config==""){
  437. return error_show(1003,"参数config不能为空");
  438. }
  439. if($other_config==""){
  440. return error_show(1003,"参数other_config不能为空");
  441. }
  442. if($specs_weight===""){
  443. return error_show(1003,"参数specs_weight不能为空");
  444. }
  445. if($gold_price===""){
  446. return error_show(1003,"参数gold_price不能为空");
  447. }
  448. }
  449. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  450. if($token==''){
  451. return error_show(102,"参数token不能为空");
  452. }
  453. $user =GetUserInfo($token);
  454. if(empty($user)||$user['code']!=0){
  455. return error_show(105,"用户数据不存在");
  456. }
  457. $specinfo=[];
  458. foreach ($specin as $v){
  459. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  460. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  461. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  462. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  463. $specinfo[]=$v;
  464. }
  465. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  466. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  467. $bidlist = Db::name("consult_bids")->where(["infoNo"=>$zxinfo['infoNo'],"is_del"=>0])->select();
  468. Db::startTrans();
  469. try{
  470. $innew =makeNo("IF");
  471. $info=[
  472. "infoNo"=>$innew,
  473. "zxNo"=>$zxinfo['zxNo'],
  474. "spuCode"=>"",
  475. "good_name"=>$good_name,
  476. "good_img"=>$good_img,
  477. "cat_id"=>$cat_id,
  478. "unit"=>$unit,
  479. "brand_id"=>$brand_id,
  480. "arrival_time"=>$arrival_time,
  481. "specinfo"=>json_encode($specinfo),
  482. // "color"=>$color,
  483. // "material"=>$material,
  484. "cost_desc"=>$cost_desc,
  485. "is_addrs"=>$is_addrs,
  486. "is_custom"=>$is_custom,
  487. "metal_id"=>$metal_id,
  488. "config"=>$config,
  489. "other_config"=>$other_config,
  490. "specs_weight"=>$specs_weight===""?0:$specs_weight,
  491. "gold_price"=>$gold_price===""? 0 : $gold_price,
  492. "is_gold_price"=>$is_gold_price===""?0:$is_gold_price,
  493. "total_weight"=>$total_weight===""? $num*$specs_weight :$total_weight,
  494. "budget_price"=>$budget_price,
  495. "num"=>$num,
  496. "pgNo"=>$pgNo,
  497. "use_desc"=>$use_desc,
  498. "remark"=>$remark,
  499. "status"=>1,
  500. "is_del"=>0,
  501. "addtime"=>date("Y-m-d H:i:s"),
  502. "updatetime"=>date("Y-m-d H:i:s"),
  503. 'bargain_status'=>1,
  504. 'enclosure_file'=>$enclosure_file
  505. ];
  506. $up = Db::name("consult_info")->insert($info);
  507. if($up){
  508. //操作记录
  509. ActionLog::logAdd($this->post['token'], [
  510. "order_code" => $innew,//咨询单详情编号
  511. "status" => 1,//这里的status是之前的值
  512. "action_remark" => '',//备注
  513. "action_type" => "edit"//新建create,编辑edit,更改状态status
  514. ], "ZXD", 1, $this->post);
  515. // ProcessOrder::AddProcess($this->post['token'], [
  516. // "order_type" => 'ZXD',
  517. // "order_code" => $innew,//咨询单详情编号
  518. // "order_id" => 0,
  519. // "order_status" => 1
  520. // ]);
  521. if (!empty($bidlist)){
  522. foreach ($bidlist as $value){
  523. unset($value['id']);
  524. $value['infoNo']=$innew;
  525. $value['bidNo']=makeNo("BD");
  526. $value['spuCode']=makeNo("SKU");
  527. $value['status'] =0;
  528. $value['updatetime'] =date("Y-m-d H:i:s");
  529. $in = Db::name("consult_bids")->insert($value);
  530. if($in==false){
  531. Db::rollback();
  532. return error_show(1004,"反馈商品新建失败");
  533. }
  534. ActionLog::logAdd($this->post['token'], [
  535. "order_code" => $innew,//咨询单详情编号
  536. "status" => 1,//这里的status是之前的值
  537. "action_remark" => '',//备注
  538. "action_type" => "edit"//新建create,编辑edit,更改状态status
  539. ], "FKD", 1, $this->post);
  540. }
  541. }
  542. $zxinfo["bargain_status"] =1;
  543. $zxinfo["bargain_code"] =$innew;
  544. $zxinfo["updatetime"] =date("Y-m-d H:i:s");
  545. $bar=Db::name("consult_info")->save($zxinfo);
  546. if($bar==false){
  547. Db::rollback();
  548. return error_show(1004,"反馈商品更新失败");
  549. }else{
  550. //修改状态,添加待办
  551. ActionLog::logAdd($this->post['token'], [
  552. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  553. "status" => $zxinfo['status'],//这里的status是之前的值
  554. "action_remark" => '',//备注
  555. "action_type" => "edit"//新建create,编辑edit,更改状态status
  556. ], "ZXD", $zxinfo['status'], $zxinfo);
  557. }
  558. //更新consule_order记录
  559. $op = Db::name('consult_order')->where('zxNo',$zxinfo['zxNo'])->update(['endtime'=>$endtime,
  560. 'updatetime'=>date('Y-m-d H:i:s')]);
  561. if($op==false){
  562. Db::rollback();
  563. return error_show(1004,'咨询单结束时间更新失败');
  564. }
  565. Db::commit();
  566. return app_show(0,"咨询新建成功",["infoNo"=>$innew]);
  567. }
  568. }catch (\Exception $e){
  569. Db::rollback();
  570. return error_show(1004,$e->getMessage());
  571. }
  572. }
  573. //** 发布竞标任务 */
  574. public function bargain(){
  575. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  576. if($infoNo==""){
  577. return error_show(1004,"参数infoNo不能为空");
  578. }
  579. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  580. if($zxinfo==false){
  581. return error_show(1004,"未找到信息数据");
  582. }
  583. $status =isset($this->post['status']) && $this->post['status']!=="" ? intval($this->post['status']):"";
  584. if($status===""){
  585. return error_show(1004,"参数status不能为空");
  586. }
  587. // if($status==1&&$zxinfo['status']>1){
  588. // $zxinfo['bargain_num']=+1;
  589. // }
  590. $old_zxinfo_status = $zxinfo['status'];
  591. $zxinfo['status']=$status;
  592. $zxinfo['updatetime']=date("Y-m-d H:i:s");
  593. $up = Db::name("consult_info")->save($zxinfo);
  594. if($up){
  595. //修改状态,添加待办
  596. ActionLog::logAdd($this->post['token'], [
  597. "order_code" => $zxinfo['infoNo'],//咨询单详情编号
  598. "status" => $old_zxinfo_status,//这里的status是之前的值
  599. "action_remark" => '',//备注
  600. "action_type" => "status"//新建create,编辑edit,更改状态status
  601. ], "ZXD", $zxinfo['status'], $zxinfo);
  602. return app_show(0,"状态更新成功");
  603. }else{
  604. return error_show(1003,"状态更新失败");
  605. }
  606. }
  607. //反馈商品添加
  608. public function feadback(){
  609. $infoNo= isset($this->post['infoNo'])&&$this->post['infoNo']!=""?trim($this->post['infoNo']):"";
  610. if($infoNo==""){
  611. return error_show(1002,"参数infoNo不能为空");
  612. }
  613. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$infoNo,"is_del"=>0])->find();
  614. if($zxinfo==false){
  615. return error_show(1003,"未找到信息数据");
  616. }
  617. if($zxinfo['status']!=1){
  618. return error_show(1004,"任务未进行");
  619. }
  620. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  621. if($zx==false){
  622. return error_show(1003,"未找咨询信息数据");
  623. }
  624. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  625. if($pname==""){
  626. return error_show(1002,"参数pname不能为空");
  627. }
  628. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  629. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  630. if($cat_id==""){
  631. return error_show(1002,"参数cat_id不能为空");
  632. }
  633. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  634. if($specin==""){
  635. return error_show(1003,"参数specinfo不能为空");
  636. }
  637. $specinfo=[];
  638. foreach ($specin as $v){
  639. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  640. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  641. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  642. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  643. $specinfo[]=$v;
  644. }
  645. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  646. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  647. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  648. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  649. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  650. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  651. :"";
  652. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  653. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  654. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  655. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  656. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"";
  657. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  658. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  659. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  660. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  661. $weight = isset($this->post['weight'])&&$this->post['weight']!==""? floatval($this->post['weight']):"0";
  662. $good_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!==""? floatval($this->post['noble_weight']):"0";
  663. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!==""? floatval($this->post['demo_fee']):"0";
  664. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!==""? floatval($this->post['delivery_fee']):"0";
  665. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!==""? floatval($this->post['open_fee']):"0";
  666. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!==""? floatval($this->post['pakge_fee']):"0";
  667. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):"0";
  668. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!==""? floatval($this->post['mark_fee']):"0";
  669. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!==""? floatval($this->post['cert_fee']):"0";
  670. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!==""? floatval($this->post['cost_fee']):"0";
  671. if($nake_fee==="" ){
  672. return error_show(1004,"参数nake_fee不能为空");
  673. }
  674. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  675. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  676. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  677. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  678. if($delivery_place==''){
  679. return error_show(1002,"参数delivery_place不能为空");
  680. }
  681. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  682. if($token==''){
  683. return error_show(1002,"参数token不能为空");
  684. }
  685. $user =GetUserInfo($token);
  686. if(empty($user)||$user['code']!=0){
  687. return error_show(1005,"用户数据不存在");
  688. }
  689. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  690. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  691. $bidNo=makeNo("BD");
  692. $spucode=makeNo("SKU");
  693. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  694. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  695. //部分参数的大小校验
  696. $vali = Validate::rule([
  697. 'expire_day|有效时长'=>'require|elt:214748364',
  698. 'delivery_day|物流时长'=>'require|elt:214748364',
  699. 'work_day|生产工期'=>'require|elt:214748364',
  700. 'weight|总重量'=>'require|max:10',
  701. ]);
  702. $temp = [
  703. 'expire_day'=>$expire_day,
  704. 'delivery_day'=>$delivery_day,
  705. 'work_day'=>$work_day,
  706. 'weight'=>$weight,
  707. ];
  708. if(!$vali->check($temp)) return error_show(0,$vali->getError());
  709. $sale_cost_fee = $cost_fee;//销售工艺费默认取传值
  710. $cat_top_list = made($cat_id);
  711. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  712. if ($is_gold_price == 1 && $cat_top_id == 6) {
  713. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  714. ->find();
  715. //$total_fee = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee*$weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  716. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  717. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $good_weight * $gold["price"] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  718. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  719. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  720. // $saleprice = ($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  721. $saleprice = $total_fee/ (1 - $budget);
  722. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  723. $sale_cost_fee = ($saleprice - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) /$good_weight - $gold["price"];
  724. }else{
  725. if($nake_fee){
  726. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight +
  727. $pakge_fee + $mark_fee + $cert_fee +$nake_fee)/ (1 - $budget);
  728. $total_fee = $demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee;
  729. }else{
  730. $saleprice = ($demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee * $good_weight + $pakge_fee + $mark_fee + $cert_fee) /
  731. (1 - $budget);
  732. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee *$good_weight + $pakge_fee + $mark_fee + $cert_fee;
  733. }
  734. }
  735. $data=[
  736. "bidNo"=>$bidNo,
  737. "infoNo"=>$infoNo,
  738. "zxNo"=>$zxinfo['zxNo'],
  739. "spuCode"=>$spucode,
  740. "good_name"=>$pname,
  741. "brand_id"=>$brandid,
  742. "cat_id"=>$cat_id,
  743. "specinfo"=>json_encode($specinfo),
  744. "unit_id"=>$unit_id,
  745. "cost_desc"=>$cost_desc,
  746. "work_day"=>$work_day,
  747. "delivery_day"=>$delivery_day,
  748. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  749. "expire_day"=>$expire_day,
  750. "origin_place"=>$origin_place,
  751. "supplierNo"=>$supplierNo,
  752. "pay_way"=>$pay_way,
  753. "tax"=>$tax,
  754. "send_way"=>$send_way,
  755. "metal_id"=>$metal_id,
  756. "is_gold_price"=>$is_gold_price,
  757. "config"=>$config,
  758. "other_config"=>$other_config,
  759. "weight"=>$weight,
  760. "good_weight"=>$good_weight,
  761. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  762. "is_diff"=>$is_diff,
  763. "demo_fee"=>$demo_fee,
  764. "delivery_fee"=>$delivery_fee,
  765. "open_fee"=>$open_fee,
  766. "pakge_fee"=>$pakge_fee,
  767. "nake_fee"=>$nake_fee,
  768. "mark_fee"=>$mark_fee,
  769. "cert_fee"=>$cert_fee,
  770. "cost_fee"=>$cost_fee,
  771. "total_fee"=>$total_fee,
  772. "supply_area"=>$supply_area,
  773. "remark"=>$remark,
  774. "sale_price"=>$saleprice,
  775. "sale_cost_fee"=>$sale_cost_fee,
  776. "origin_cost_fee"=>$sale_cost_fee,
  777. "origin_price"=>$saleprice,
  778. "createrid"=>$createrid,
  779. "creater"=>$creater,
  780. "status"=>$zxinfo['status']==1 ?1 :2,
  781. "is_del"=>0,
  782. "addtime"=>date("Y-m-d H:i:s"),
  783. "updatetime"=>date("Y-m-d H:i:s"),
  784. 'delivery_place'=>$delivery_place//发货地
  785. ];
  786. Db::startTrans();
  787. try{
  788. $insert= Db::name("consult_bids")->insert($data);
  789. if($insert){
  790. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  791. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  792. if($projectinfo==false){
  793. Db::rollback();
  794. return error_show(1006,"未找到项目信息");
  795. }
  796. $temp=[];
  797. $temp['spuCode']=$spucode;
  798. $temp['skuCode']="";
  799. $temp['pgNo']=$zxinfo['pgNo'];
  800. $temp['projectNo']=$zx['projectNo'];
  801. $temp['good_name']=$pname;
  802. $temp['good_type']=$projectinfo['good_type'];
  803. $temp['data_source']=2;
  804. $temp['cat_id']=$cat_id;
  805. $temp['budget_price']=$projectinfo['budget_price'];
  806. $temp['sale_price']=$saleprice;
  807. $temp['origin_price']=$total_fee;
  808. $temp['num']=$zxinfo['num'];
  809. $temp['status']=0;
  810. $temp['is_del']=0;
  811. $temp['creater']=$creater;
  812. $temp['createrid']=$createrid;
  813. $temp['addtime']=date("Y-m-d H:i:s");
  814. $temp['updatetime']=date("Y-m-d H:i:s");
  815. $nu = Db::name("project_feedback")->insert($temp);
  816. if($nu==false){
  817. Db::rollback();
  818. return error_show(1006,"项目反馈失败");
  819. }else{
  820. $old_projectinfo_status = $projectinfo['status'];
  821. $projectinfo['status']=2;
  822. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  823. $up = Db::name("project_info")->save($projectinfo);
  824. if($up){
  825. //修改状态,添加待办,只记录动作
  826. ActionLog::logAdd($this->post['token'], [
  827. "order_code" => $projectinfo['pgNo'],//编码
  828. "status" => $old_projectinfo_status,//这里的status是之前的值
  829. "action_remark" => '',//备注
  830. "action_type" => "status"//新建create,编辑edit,更改状态status
  831. ], "PRI", 2, $projectinfo);
  832. $count = Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])
  833. ->count();
  834. if($count==0){
  835. $projetc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->find();
  836. if($projetc!=false){
  837. $proc =Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'],"status"=>1])->save
  838. (["status"=>2,"updatetime"=>date("Y-m-d H:i:s")]);
  839. if($proc==false){
  840. Db::rollback();
  841. return error_show(1006,"项目反馈失败");
  842. }else{
  843. //修改状态,添加待办
  844. ActionLog::logAdd($this->post['token'], [
  845. "order_code" => $projetc['projectNo'],//项目编码
  846. "status" => 1,//这里的status是之前的值
  847. "action_remark" => '',//备注
  848. "action_type" => "status"//新建create,编辑edit,更改状态status
  849. ], "PRO", 2, $projetc);
  850. ProcessOrder::AddProcess($this->post['token'], [
  851. "order_type" => 'PRO',
  852. "order_code" => $projetc['projectNo'],
  853. "order_id" => $projetc['id'],
  854. "order_status" => 2,"before_status"=>1
  855. ]);
  856. }
  857. }
  858. }
  859. }
  860. }
  861. }
  862. Db::commit();
  863. return app_show(0,"反馈成功",["bidNo"=>$bidNo]);
  864. }else{
  865. Db::rollback();
  866. return error_show(1006,"反馈失败");
  867. }
  868. }catch (\Exception $e){
  869. Db::rollback();
  870. return error_show(1006,$e->getMessage());
  871. }
  872. }
  873. //反馈商品详情
  874. public function feadinfo(){
  875. $bidNo =isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  876. if($bidNo==""){
  877. return error_show(1004,"参数bidNo不能为空");
  878. }
  879. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  880. if($info==false){
  881. return error_show(1004,"未找到商品数据");
  882. }
  883. $unit =Db::name("unit")->where(["id"=>$info['unit_id']])->find();
  884. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  885. $info['cat_info'] = made($info['cat_id'],[]);
  886. $info['noble_weight'] = $info['good_weight'];
  887. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  888. $info['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  889. if($info['brand_id']!=0){
  890. $brand=Db::name("brand")->where(["id"=>$info['brand_id']])->find();
  891. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  892. }else{
  893. $info["brand_name"]="";
  894. $info["brand_id"]="";
  895. }
  896. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  897. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  898. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  899. $god=[
  900. "metal_id"=>$info['metal_id'],
  901. "weight"=>$info["good_weight"],
  902. "demo_fee"=>$info["demo_fee"],
  903. "delivery_fee"=>$info["delivery_fee"],
  904. "open_fee"=>$info["open_fee"],
  905. "packing_fee"=>$info["pakge_fee"],
  906. "mark_fee"=>$info["mark_fee"],
  907. "nake_fee"=>$info["nake_fee"],
  908. "cert_fee"=>$info["cert_fee"],
  909. "cost_fee"=>$info["cost_fee"],
  910. "num"=>$bidinfo["num"],
  911. ];
  912. if($info['is_gold_price']==1){
  913. $price = GoldPrice($god, $budget/100);
  914. $info['sale_price'] =round($price,2);
  915. }
  916. $info['specinfo'] = json_decode($info['specinfo'],true);
  917. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  918. if($info['delivery_place']!=""){
  919. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['delivery_place']);
  920. }
  921. $info['delivery_place_cn']=GetAddr(json_encode($place));
  922. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  923. if($info['origin_place']!=""){
  924. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$info['origin_place']);
  925. }
  926. $info['origin_place_cn']=GetAddr(json_encode($place));
  927. $info['metal_name']=isset($info['metal_id'])&& $info['metal_id']!=0?$this->noble[$info['metal_id']]:"";
  928. $bargain =Db::name("bargain_order")->where(['bidsNo'=>$bidNo,"is_del"=>0])->find();
  929. $info['bargain'] =$bargain;
  930. $info['good_img'] = explode(',',$info['good_img']);
  931. return app_show(0,"获取成功",$info);
  932. }
  933. //反馈商品编辑
  934. public function feededit(){
  935. $bidNo= isset($this->post['bidNo'])&&$this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  936. if($bidNo==""){
  937. return error_show(1002,"参数bidNo不能为空");
  938. }
  939. $bidinfo = Db::name("consult_bids")->where(["bidNo"=>$bidNo,"is_del"=>0])->find();
  940. if($bidinfo==false){
  941. return error_show(1003,"未找到信息数据");
  942. }
  943. if($bidinfo['status']>=5){
  944. return error_show(1004,"咨询单已确认无法修改");
  945. }
  946. $zxinfo = Db::name("consult_info")->where(["infoNo"=>$bidinfo['infoNo'],"is_del"=>0])->find();
  947. if($zxinfo==false){
  948. return error_show(1003,"未找到信息数据");
  949. }
  950. $zx = Db::name("consult_order")->where(["zxNo"=>$zxinfo['zxNo'],"is_del"=>0])->find();
  951. if($zx==false){
  952. return error_show(1003,"未找咨询信息数据");
  953. }
  954. $pname = isset($this->post['pname'])&&$this->post['pname']!=""? trim($this->post['pname']):"";
  955. if($pname==""){
  956. return error_show(1002,"参数pname不能为空");
  957. }
  958. $brandid = isset($this->post['brandid'])&&$this->post['brandid']!=""? intval($this->post['brandid']):"";
  959. // if($brandid==""){
  960. // return error_show(1002,"参数brandid不能为空");
  961. // }
  962. $cat_id = isset($this->post['cat_id'])&&$this->post['cat_id']!=""? trim($this->post['cat_id']):"";
  963. if($cat_id==""){
  964. return error_show(1002,"参数cat_id不能为空");
  965. }
  966. $specin= isset($this->post['specinfo'])&&!empty($this->post['specinfo'])?$this->post['specinfo']:"";
  967. if($specin==""){
  968. return error_show(1003,"参数specinfo不能为空");
  969. }
  970. $specinfo=[];
  971. foreach ($specin as $v){
  972. $spec =Db::name("specs")->where(["id"=>$v['specid']])->find();
  973. $spec_value =Db::name("spec_value")->where(["id"=>$v['spec_value_id']])->find();
  974. $v['spec_name']=isset($spec['spec_name'])?$spec['spec_name']:"";
  975. $v['spec_value_name']=isset($spec_value['spec_value'])?$spec_value['spec_value']:"";
  976. $specinfo[]=$v;
  977. }
  978. $unit_id = isset($this->post['unit_id'])&&$this->post['unit_id']!=""? intval($this->post['unit_id']):"";
  979. $cost_desc = isset($this->post['cost_desc'])&&$this->post['cost_desc']!=""? trim($this->post['cost_desc']):"";
  980. $work_day = isset($this->post['work_day'])&&$this->post['work_day']!=""? intval($this->post['work_day']):"";
  981. $delivery_day = isset($this->post['delivery_day'])&&$this->post['delivery_day']!=""? intval($this->post['delivery_day']):"";
  982. $good_img = isset($this->post['good_img'])&&$this->post['good_img']!=""? $this->post['good_img']:[];
  983. $expire_day = isset($this->post['expire_day'])&&$this->post['expire_day']!=""? intval($this->post['expire_day'])
  984. :"";
  985. $origin_place = isset($this->post['origin_place'])&&$this->post['origin_place']!=""? trim($this->post['origin_place']):"";
  986. $supplierNo = isset($this->post['supplierNo'])&&$this->post['supplierNo']!=""? trim($this->post['supplierNo']):"";
  987. $pay_way = isset($this->post['pay_way'])&&$this->post['pay_way']!=""? intval($this->post['pay_way']):"";
  988. $tax = isset($this->post['tax'])&&$this->post['tax']!=""? trim($this->post['tax']):"";
  989. $send_way = isset($this->post['send_way'])&&$this->post['send_way']!=""? intval($this->post['send_way']):"0";
  990. $metal_id = isset($this->post['metal_id'])&&$this->post['metal_id']!=""? intval($this->post['metal_id']):"0";
  991. $is_gold_price = isset($this->post['is_gold_price'])&&$this->post['is_gold_price']!=""? intval($this->post['is_gold_price']):"0";
  992. $config = isset($this->post['config'])&&$this->post['config']!=""? $this->post['config']:"";
  993. $other_config = isset($this->post['other_config'])&&$this->post['other_config']!=""? $this->post['other_config']:"";
  994. $weight = isset($this->post['weight'])&&$this->post['weight']!=""? floatval($this->post['weight']):"0";
  995. $noble_weight = isset($this->post['noble_weight'])&&$this->post['noble_weight']!=""? floatval($this->post['noble_weight']):"0";
  996. $demo_fee = isset($this->post['demo_fee'])&&$this->post['demo_fee']!=""? floatval($this->post['demo_fee']):"0";
  997. $delivery_fee = isset($this->post['delivery_fee'])&&$this->post['delivery_fee']!=""? floatval($this->post['delivery_fee']):"0";
  998. $open_fee = isset($this->post['open_fee'])&&$this->post['open_fee']!=""? floatval($this->post['open_fee']):"0";
  999. $pakge_fee = isset($this->post['pakge_fee'])&&$this->post['pakge_fee']!=""? floatval($this->post['pakge_fee']):"0";
  1000. $nake_fee = isset($this->post['nake_fee'])&&$this->post['nake_fee']!==""? floatval($this->post['nake_fee']):0;
  1001. $mark_fee = isset($this->post['mark_fee'])&&$this->post['mark_fee']!=""? floatval($this->post['mark_fee']):"0";
  1002. $cert_fee = isset($this->post['cert_fee'])&&$this->post['cert_fee']!=""? floatval($this->post['cert_fee']):"0";
  1003. $cost_fee = isset($this->post['cost_fee'])&&$this->post['cost_fee']!=""? floatval($this->post['cost_fee']):"0";
  1004. $is_diff = isset($this->post['is_diff'])&&$this->post['is_diff']!==""? intval($this->post['is_diff']):"";
  1005. $supply_area = isset($this->post['supply_area'])&&$this->post['supply_area']!==""? intval($this->post['supply_area']):"";
  1006. $remark = isset($this->post['remark'])&&$this->post['remark']!=""? trim($this->post['remark']):"";
  1007. $delivery_place = isset($this->post['delivery_place'])&& $this->post['delivery_place']!='' ? trim($this->post['delivery_place']):"";
  1008. if($delivery_place==''){
  1009. return error_show(1002,"参数delivery_place不能为空");
  1010. }
  1011. $catinfo = Db::name("cat")->where(["id"=>$cat_id])->find();
  1012. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1013. $sale_cost_fee = $bidinfo['sale_cost_fee'];
  1014. $cat_top_list = made($cat_id);
  1015. $cat_top_id = isset($cat_top_list[0]['id']) ? $cat_top_list[0]['id'] : 0;
  1016. if ($is_gold_price == 1 && $cat_top_id == 6) {
  1017. $gold = Db::name("gold_price1")->where(["type"=>$metal_id,"is_del"=>0,"status"=>1])->order("addtime desc")
  1018. ->find();
  1019. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1020. $total_fee = $demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $noble_weight * $gold["price"] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee;
  1021. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1022. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1023. $saleprice = $total_fee / (1 - $budget);
  1024. //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1025. $sale_cost_fee = ( $saleprice- ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $noble_weight - $gold["price"];
  1026. }else{
  1027. $saleprice = ($demo_fee / $zxinfo['num']+$delivery_fee+$open_fee / $zxinfo['num'] + $cost_fee*$noble_weight + $pakge_fee +
  1028. $mark_fee + $cert_fee + $nake_fee) / (1 - $budget);
  1029. $total_fee = $demo_fee/$zxinfo['num']+$delivery_fee+$open_fee/$zxinfo['num'] + $cost_fee * $noble_weight + $pakge_fee + $mark_fee+$cert_fee +$nake_fee;
  1030. }
  1031. Db::startTrans();
  1032. try{
  1033. $data=[
  1034. "good_name"=>$pname,
  1035. "brand_id"=>$brandid,
  1036. "cat_id"=>$cat_id,
  1037. "specinfo"=>json_encode($specinfo),
  1038. // "material"=>$material,
  1039. "unit_id"=>$unit_id,
  1040. "cost_desc"=>$cost_desc,
  1041. "work_day"=>$work_day,
  1042. "delivery_day"=>$delivery_day,
  1043. "good_img"=>is_array($good_img)?implode(',',$good_img):$good_img,
  1044. "expire_day"=>$expire_day,
  1045. "origin_place"=>$origin_place,
  1046. "supplierNo"=>$supplierNo,
  1047. "pay_way"=>$pay_way,
  1048. "tax"=>$tax,
  1049. "send_way"=>$send_way,
  1050. "metal_id"=>$metal_id,
  1051. "is_gold_price"=>$is_gold_price,
  1052. "config"=>$config,
  1053. "other_config"=>$other_config,
  1054. "weight"=>$weight,
  1055. "good_weight"=>$noble_weight,
  1056. "is_diff"=>$is_diff,
  1057. "demo_fee"=>$demo_fee,
  1058. "gold_price"=>isset($gold["price"])?$gold["price"]:0,
  1059. "delivery_fee"=>$delivery_fee,
  1060. "open_fee"=>$open_fee,
  1061. "pakge_fee"=>$pakge_fee,
  1062. "nake_fee"=>$nake_fee,
  1063. "mark_fee"=>$mark_fee,
  1064. "cert_fee"=>$cert_fee,
  1065. "cost_fee"=>$cost_fee,
  1066. "sale_cost_fee"=>$sale_cost_fee,
  1067. "origin_cost_fee"=>$sale_cost_fee,
  1068. "total_fee"=>$total_fee,
  1069. "sale_price"=>$saleprice,
  1070. "origin_price"=>$saleprice,
  1071. "supply_area"=>$supply_area,
  1072. "remark"=>$remark,
  1073. "status"=>0,
  1074. "updatetime"=>date("Y-m-d H:i:s"),
  1075. 'delivery_place' => $delivery_place
  1076. ];
  1077. $insert= Db::name("consult_bids")->where($bidinfo)->save($data);
  1078. if($insert){
  1079. if($zxinfo['bargain_status']==1){
  1080. $zxinfo['bargain_status']=0;
  1081. $infoip =Db::name("consult_info")->save($zxinfo);
  1082. if($infoip==false){
  1083. Db::rollback();
  1084. return error_show(1006,"咨询信息状态更新失败");
  1085. }
  1086. }
  1087. if($zx['is_project']==1 && $zx['projectNo']!="" && $zxinfo['pgNo']!=""){
  1088. $projectinfo =Db::name("project_info")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"is_del"=>0])->find();
  1089. if($projectinfo==false){
  1090. Db::rollback();
  1091. return error_show(1006,"未找到项目信息");
  1092. }
  1093. $feed = Db::name("project_feedback")->where(["pgNo"=>$zxinfo["pgNo"],"projectNo"=>$zx['projectNo'],"spuCode"=>$bidinfo['spuCode'],"is_del"=>0])->find();
  1094. if($feed!=false) {
  1095. $feed['good_name']=$pname;
  1096. $feed['good_type']=$projectinfo['good_type'];
  1097. $feed['cat_id']=$cat_id;
  1098. $feed['sale_price']=$saleprice;
  1099. $feed['origin_price']=$total_fee;
  1100. $feed['updatetime']=date("Y-m-d H:i:s");
  1101. $temp['updatetime']=date("Y-m-d H:i:s");
  1102. $nu=Db::name("project_feedback")->save($feed);
  1103. if ($nu == false) {
  1104. Db::rollback();
  1105. return error_show(1006 , "项目反馈失败");
  1106. } else {
  1107. $old_projectinfo_status=$projectinfo['status'];
  1108. $projectinfo['status']=2;
  1109. $projectinfo['updatetime']=date("Y-m-d H:i:s");
  1110. $up=Db::name("project_info")->save($projectinfo);
  1111. if ($up) {
  1112. //修改状态,添加待办,只记录动作
  1113. ActionLog::logAdd($this->post['token'] , [
  1114. "order_code"=>$projectinfo['pgNo'] ,//编码
  1115. "status"=>$old_projectinfo_status ,//这里的status是之前的值
  1116. "action_remark"=>'' ,//备注
  1117. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1118. ] , "PRI" , 2 , $projectinfo
  1119. );
  1120. $count=Db::name("project_info")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->count();
  1121. if ($count == 0) {
  1122. //先查询是否存在status==1的项目,有的话再更新,否则跳过
  1123. $project_id=Db::name("project")->where(["projectNo"=>$projectinfo['projectNo'] , "status"=>1])->value('id' , 0);
  1124. if ($project_id) {
  1125. $proc=Db::name("project")->where(["id"=>$project_id])->update(["status"=>2 , "updatetime"=>date("Y-m-d H:i:s")]);
  1126. if ($proc == false) {
  1127. Db::rollback();
  1128. return error_show(1006 , "项目反馈失败");
  1129. } else {
  1130. //修改状态,添加待办
  1131. ActionLog::logAdd($this->post['token'] , [
  1132. "order_code"=>$projectinfo['projectNo'] ,//项目编码
  1133. "status"=>1 ,//这里的status是之前的值
  1134. "action_remark"=>'' ,//备注
  1135. "action_type"=>"status"//新建create,编辑edit,更改状态status
  1136. ] , "PRO" , 2 , $this->post
  1137. );
  1138. ProcessOrder::AddProcess($this->post['token'] , [
  1139. "order_type"=>'PRO' ,
  1140. "order_code"=>$projectinfo['projectNo'] ,
  1141. "order_id"=>$project_id ,
  1142. "order_status"=>2 , "before_status"=>1
  1143. ]
  1144. );
  1145. }
  1146. }
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152. Db::commit();
  1153. return app_show(0,"编辑成功");
  1154. }else{
  1155. Db::rollback();
  1156. return error_show(1004,"编辑失败");
  1157. }
  1158. }catch (\Exception $e){
  1159. Db::rollback();
  1160. return error_show(1004,$e->getMessage());
  1161. }
  1162. }
  1163. //生成议价单
  1164. public function bargain_add(){
  1165. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1166. if($bidNo===""){
  1167. return error_show(1004,"参数bidNo不能为空");
  1168. }
  1169. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1170. if($info==false){
  1171. return error_show(1004,"未找到商品数据");
  1172. }
  1173. $consult =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1174. if($consult==false){
  1175. return error_show(1004,"未找到咨询数据");
  1176. }
  1177. $bargain_price = isset($this->post['bargain_price'])&& $this->post['bargain_price']!=""?floatval($this->post['bargain_price']):"";
  1178. if($bargain_price===""){
  1179. return error_show(1004,"参数bargain_price不能为空");
  1180. }
  1181. $cost_price = isset($this->post['cost_price'])&& $this->post['cost_price']!=""?floatval($this->post['cost_price']):"";
  1182. if($info['is_gold_price']==1){
  1183. if($cost_price==""){
  1184. return error_show(1004,"参数cost_price不能为空");
  1185. }
  1186. $catinfo = Db::name("cat")->where(["id"=>$info['cat_id']])->find();
  1187. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1188. $gold = Db::name("gold_price1")->where(["type"=>$info['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1189. ->find();
  1190. $bargain_price = ($info['demo_fee']/$consult['num']+$info['delivery_fee']+$info['open_fee']/$consult['num']+$info['good_weight'] * $gold["price"] + $cost_price *$info['good_weight']+$info['pakge_fee']+$info['mark_fee'] +$info['cert_fee'] +$info['nake_fee']) / (1 - $budget);
  1191. }
  1192. $bargain_reason = isset($this->post['bargain_reason'])&& $this->post['bargain_reason']!=""?trim($this->post['bargain_reason']):"";
  1193. // if($bargain_reason===""){
  1194. // return error_show(1004,"参数bargain_reason不能为空");
  1195. // }
  1196. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1197. if($infos==false){
  1198. return error_show(1004,"未找到商品数据");
  1199. }
  1200. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1201. return error_show(1004,"咨询单招标未结束或已确认商品");
  1202. }
  1203. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1204. if($token==''){
  1205. return error_show(105,"参数token不能为空");
  1206. }
  1207. $user =GetUserInfo($token);
  1208. if(empty($user)||$user['code']!=0){
  1209. return error_show(1002,"用户数据不存在");
  1210. }
  1211. //新增两个字段
  1212. //议价备注
  1213. $bargain_remark = isset($this->post['bargain_remark']) && $this->post['bargain_remark'] != "" ? trim($this->post['bargain_remark']) : "";
  1214. //议价原因id
  1215. $result_info_id = isset($this->post['result_info_id']) && $this->post['result_info_id'] != "" ? $this->post['result_info_id'] : "";
  1216. if ($result_info_id != '') {
  1217. $temp = Db::name('result_info')->field('id')->where(['result_code' => $result_info_id, 'type' => 7, 'status' => 1, 'is_del' => 0])->find();//type 7议价原因
  1218. if (empty($temp)) return error_show(1004, "议价原因选择不正确");
  1219. }
  1220. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1221. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1222. $bargainNo =makeNo("BA");
  1223. Db::startTrans();//::todo 金价 毛利计算
  1224. try{
  1225. $data=[
  1226. "bidsNo"=>$bidNo,
  1227. "infoNo"=>$info['infoNo'],
  1228. "zxNo"=>$info['zxNo'],
  1229. "bargainNo"=>$bargainNo,
  1230. "bargain_type"=>1,
  1231. "bargain_reason"=>$bargain_reason,
  1232. "sale_price"=>$info['sale_price'],
  1233. "cost_before_price"=>$info['sale_cost_fee'],
  1234. "cost_after_price"=>$cost_price,
  1235. "before_rate"=>round(($info['origin_price']-$info['total_fee'])/$info['origin_price'],2),
  1236. "after_rate"=>round(($bargain_price-$info['total_fee'])/$bargain_price,2),
  1237. "after_price"=>$bargain_price,
  1238. "exam_info"=>"",
  1239. "status"=>0,
  1240. "is_del"=>0,
  1241. "creater"=>$creater,
  1242. "createrid"=>$createrid,
  1243. "addtime"=>date("Y-m-d H:i:s"),
  1244. "updatetime"=>date("Y-m-d H:i:s"),
  1245. 'bargain_remark'=>$bargain_remark,
  1246. 'result_info_id'=>$result_info_id,
  1247. ];
  1248. $int = Db::name("bargain_order")->insert($data);
  1249. if($int){
  1250. //修改状态,添加待办
  1251. ActionLog::logAdd($this->post['token'], [
  1252. "order_code" => $bargainNo,//咨询单详情编号
  1253. "status" => 0,//这里的status是之前的值
  1254. "action_remark" => '',//备注
  1255. "action_type" => "status"//新建create,编辑edit,更改状态status
  1256. ], "YJD", $data['status'], $data);
  1257. ProcessOrder::AddProcess($this->post['token'], [
  1258. "order_type" => 'YJD',
  1259. "order_code" => $bargainNo,
  1260. "order_id" =>Db::name("bargain_order")->getLastInsID(),
  1261. "order_status" =>0,"before_status"=>0
  1262. ]);
  1263. $odlstatus=$info['status'];
  1264. $info['status']=3;
  1265. $info['updatetime']=date("Y-m-d H:i:s");
  1266. $up =Db::name("consult_bids")->save($info);
  1267. if($up){
  1268. //修改状态,添加待办
  1269. ActionLog::logAdd($this->post['token'], [
  1270. "order_code" => $bidNo,//咨询单详情编号
  1271. "status" => $odlstatus,//这里的status是之前的值
  1272. "action_remark" => '',//备注
  1273. "action_type" => "status"//新建create,编辑edit,更改状态status
  1274. ], "FKD", $info['status'], $info);
  1275. $old_infos_status = $infos['status'];
  1276. $infos['status']=3;
  1277. $infos['updatetime']=date("Y-m-d H:i:s");
  1278. $ups =Db::name("consult_info")->save($infos);
  1279. if($ups){
  1280. //修改状态,添加待办
  1281. ActionLog::logAdd($this->post['token'], [
  1282. "order_code" => $infos['infoNo'],//咨询单详情编号
  1283. "status" => $old_infos_status,//这里的status是之前的值
  1284. "action_remark" => '',//备注
  1285. "action_type" => "status"//新建create,编辑edit,更改状态status
  1286. ], "ZXD", $infos['status'], $infos);
  1287. //维护台账信息
  1288. Db::name('standing_book')->where('infoNo', $info['infoNo'])->update(['bargainNo' => $bargainNo,'updatetime' => date('Y-m-d H:i:s')]);
  1289. Db::commit();
  1290. return app_show(0,"议价单生成成功",["bargainNo"=>$bargainNo]);
  1291. }
  1292. }
  1293. }
  1294. Db::rollback();
  1295. return error_show(1004,"议价单新建失败");
  1296. }catch (\Exception $e){
  1297. Db::rollback();
  1298. return error_show(1004,$e->getMessage());
  1299. }
  1300. }
  1301. //选择商品
  1302. public function bids_check(){
  1303. $bidNo = isset($this->post['bidNo'])&& $this->post['bidNo']!=""?trim($this->post['bidNo']):"";
  1304. if($bidNo===""){
  1305. return error_show(1004,"参数bidNo不能为空");
  1306. }
  1307. $info =Db::name("consult_bids")->where(['bidNo'=>$bidNo,"is_del"=>0])->find();
  1308. if($info==false){
  1309. return error_show(1004,"未找到商品数据");
  1310. }
  1311. $infos =Db::name("consult_info")->where(['infoNo'=>$info['infoNo'],"is_del"=>0])->find();
  1312. if($infos==false){
  1313. return error_show(1004,"未找到商品数据");
  1314. }
  1315. if($infos['status']!=2&&$infos['status']!=3&&$infos['status']!=7){
  1316. return error_show(1004,"咨询单招标未结束或已确认商品");
  1317. }
  1318. Db::startTrans();
  1319. try {
  1320. $oldstattus=$info['status'];
  1321. $info['status']=6;
  1322. $info['updatetime']=date("Y-m-d H:i:s");
  1323. $bids = Db::name("consult_bids")->save($info);
  1324. if($bids){
  1325. //修改状态,添加待办
  1326. ActionLog::logAdd($this->post['token'], [
  1327. "order_code" =>$bidNo,//咨询单详情编号
  1328. "status" => $oldstattus,//这里的status是之前的值
  1329. "action_remark" => '',//备注
  1330. "action_type" => "status"//新建create,编辑edit,更改状态status
  1331. ], "FKD", $info['status'], $info);
  1332. $old_infos_status = $infos['status'];
  1333. $infos['status']=4;
  1334. $infos['updatetime']=date("Y-m-d H:i:s");
  1335. $se = Db::name("consult_info")->save($infos);
  1336. if($se){
  1337. //修改状态,添加待办
  1338. ActionLog::logAdd($this->post['token'], [
  1339. "order_code" => $infos['infoNo'],//咨询单详情编号
  1340. "status" => $old_infos_status,//这里的status是之前的值
  1341. "action_remark" => '',//备注
  1342. "action_type" => "status"//新建create,编辑edit,更改状态status
  1343. ], "ZXD", $infos['status'], $infos);
  1344. Db::commit();
  1345. return app_show(0,"商品确定成功");
  1346. }
  1347. }
  1348. Db::rollback();
  1349. return error_show(1004,"商品确认失败");
  1350. }catch (\Exception $e){
  1351. Db::rollback();
  1352. return error_show(1004,$e->getMessage());
  1353. }
  1354. }
  1355. //议价审核
  1356. /**
  1357. * status:
  1358. * 0待审核 1业务主管审核通过 2 业务税率未通过 3 业务驳回 4 专员通过 5 专员驳回 6 财务通过 7 财务税率未通过 8财务驳回 9 boss通过 10 boss 税率越线通过 11 驳回
  1359. */
  1360. public function bargain_status(){
  1361. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1362. if($bargainNo===""){
  1363. return error_show(1004,"参数bargainNo不能为空");
  1364. }
  1365. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1366. if($info==false){
  1367. return error_show(1004,"未找到议价数据");
  1368. }
  1369. $bids=Db::name("consult_bids")->where(["bidNo"=>$info["bidsNo"],"is_del"=>0])->find();
  1370. if($bids==false){
  1371. return error_show(1004,"未找到商品数据");
  1372. }
  1373. $coninfo=Db::name("consult_info")->where(["infoNo"=>$bids["infoNo"],"is_del"=>0])->find();
  1374. if($coninfo==false){
  1375. return error_show(1004,"未找到咨询单数据");
  1376. }
  1377. $status = isset($this->post['status'])&& $this->post['status']!=='' ? intval($this->post['status']):"";
  1378. if($status===''){
  1379. return error_show(1005,"参数status不能为空");
  1380. }
  1381. $catinfo = Db::name("cat")->where(["id"=>$bids['cat_id']])->find();
  1382. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']/100:0;
  1383. $rate = isset($catinfo['rate']) ? $catinfo['rate']/100:0; //业务主管利率
  1384. $money_rate = isset($catinfo['money_rate']) ? $catinfo['money_rate']/100:0;//财务主管利率
  1385. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1386. if($bids['is_gold_price']==1){
  1387. $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1388. ->find();
  1389. // $saleprice = $open_fee/$zxinfo['num'] + $weight* $gold["price"] + $cost_fee/(1-$budget)* $weight+$pakge_fee+$mark_fee+$cert_fee+$nake_fee;
  1390. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1391. $total_fe= $bids['demo_fee'] / $coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] / $coninfo['num'] +
  1392. $bids['good_weight']*$gold["price"] +$bids['cost_fee']*$bids['good_weight'] + $bids['pakge_fee'] +$bids['mark_fee'] + $bids['cert_fee'] + $bids['nake_fee'];
  1393. $saleprice =$total_fe / (1 - $budget);
  1394. $rate_price = $total_fe / (1 - $rate);
  1395. $money_price =$total_fe / (1 - $money_rate);
  1396. $lower_price =$total_fe / (1 - $lower_rate);
  1397. }else{
  1398. $total_fe= $bids['demo_fee']/$coninfo['num']+$bids['delivery_fee']+$bids['open_fee'] /
  1399. $coninfo['num']+$bids['cost_fee']*$bids['good_weight']+$bids['pakge_fee'] +$bids['mark_fee']+ $bids['cert_fee'] + $bids['nake_fee'];
  1400. if($bids['nake_fee']!=0){
  1401. $saleprice = ($total_fe)/ (1 - $budget);
  1402. $rate_price = ($total_fe)/ (1 - $rate);
  1403. $money_price =($total_fe)/ (1 - $money_rate);
  1404. $lower_price = ($total_fe) / (1 - $lower_rate);
  1405. }else{
  1406. $saleprice = $total_fe / (1 - $budget);
  1407. $rate_price =$total_fe/ (1 - $rate);
  1408. $money_price =$total_fe / (1 - $money_rate);
  1409. $lower_price = $total_fe/ (1 - $lower_rate);
  1410. }
  1411. }
  1412. $ra_status = $info['status'];
  1413. if($status==1){
  1414. if($info['status']==0){
  1415. if($info['after_price']<$rate_price){
  1416. $info['status']=2;
  1417. }else{
  1418. $info['status']=1;
  1419. }
  1420. }elseif($info['status']==2){
  1421. $info['status']=4;
  1422. }elseif($info['status']==4||$info['status']==5){
  1423. if($info['after_price']<$money_price){
  1424. $info['status']=7;
  1425. }else{
  1426. $info['status']=6;
  1427. }
  1428. }elseif($info['status']==7){
  1429. $info['lower_price'] =$lower_price;
  1430. if($info['after_price']<$lower_price){
  1431. $info['status']=10;
  1432. }else{
  1433. $info['status']=9;
  1434. }
  1435. }
  1436. }else{
  1437. if($info['status']==0){
  1438. $info['status']=3;
  1439. }elseif($info['status']==2){
  1440. $info['status']=4;
  1441. }elseif($info['status']==4||$info['status']==5){
  1442. $info['status']=8;
  1443. }elseif($info['status']==7){
  1444. $info['lower_price'] =$lower_price;
  1445. $info['status']=11;
  1446. }
  1447. }
  1448. $remark = isset($this->post['remark'])&& $this->post['remark']!=""?trim($this->post['remark']):"";
  1449. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1450. if($token==''){
  1451. return error_show(105,"参数token不能为空");
  1452. }
  1453. $user =GetUserInfo($token);
  1454. if(empty($user)||$user['code']!=0){
  1455. return error_show(1002,"用户数据不存在");
  1456. }
  1457. $createrid= isset($user["data"]['id']) ? $user["data"]['id'] : "";
  1458. $creater= isset($user["data"]['nickname']) ? $user["data"]['nickname'] : "";
  1459. Db::startTrans();
  1460. try{
  1461. $examinfo = isset($info['exam_info'])&&$info['exam_info']!="" ? json_decode($info['exam_info'],true):[];
  1462. $examinfo[]=["status"=>$status,"info_status"=>$ra_status,"remark"=>$remark,"createrid"=>$createrid,
  1463. "creater"=>$creater];
  1464. // $info['status'] =$status;
  1465. $info['remark'] =$remark;
  1466. $info['exam_info']=json_encode($examinfo) ;
  1467. $info['updatetime'] =date("Y-m-d H:i:s");
  1468. $up =Db::name("bargain_order")->save($info);
  1469. if($up){
  1470. //修改状态,添加待办
  1471. ActionLog::logAdd($this->post['token'], [
  1472. "order_code" => $bargainNo,//咨询单详情编号
  1473. "status" =>$ra_status,//这里的status是之前的值
  1474. "action_remark" => '',//备注
  1475. "action_type" => "status"//新建create,编辑edit,更改状态status
  1476. ], "YJD", $info['status'], $info);
  1477. $process=["order_code"=>$bargainNo,"order_id"=>$info['id'],"order_status"=>$info['status'],"order_type"=>'YJD',"before_status"=>$ra_status];
  1478. ProcessOrder::AddProcess($token,$process);
  1479. if($info['status']==1||$info['status']==3||$info['status']==8||$info['status']==6||$info['status']==9||$info['status']==10||$info['status']==11){
  1480. $bidstatus=$bids['status'];
  1481. $bids['status']=5;
  1482. if($info['status']==1||$info['status']==6||$info['status']==9||$info['status']==10){
  1483. $bids['sale_price']=$info['after_price'];
  1484. if($bids['is_gold_price']==1){
  1485. // $gold = Db::name("gold_price1")->where(["type"=>$bids['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1486. // ->find();
  1487. // $bids['sale_price']= ($bids['open_fee'] / $coninfo['num'] + $bids['weight'] * $gold["price"] + $info['cost_after_price'] *$bids['weight'] +
  1488. // $bids['pakge_fee'] + $bids['mark_fee'] +$bids['cert_fee'] +$bids['nake_fee']) /(1 - $budget);
  1489. $bids['sale_cost_fee'] = $info['cost_after_price'];
  1490. $bids['gold_price'] =isset($gold["price"])?$gold["price"]:0;
  1491. }
  1492. }
  1493. $bids['updatetime']=date("Y-m-d H:i:s");
  1494. $up =Db::name("consult_bids")->save($bids);
  1495. if($up==false){
  1496. Db::rollback();
  1497. return error_show(1004,"数据更新失败");
  1498. }
  1499. ActionLog::logAdd($this->post['token'], [
  1500. "order_code" => $info["bidsNo"],//咨询单详情编号
  1501. "status" => $bidstatus,//这里的status是之前的值
  1502. "action_remark" => '',//备注
  1503. "action_type" => "status"//新建create,编辑edit,更改状态status
  1504. ], "FKD", $bids['status'], $bids);
  1505. }
  1506. Db::commit();
  1507. return app_show(0,"更新成功");
  1508. }
  1509. }catch (\Exception $e){
  1510. Db::rollback();
  1511. return error_show(1004,$e->getMessage());
  1512. }
  1513. }
  1514. public function bargain_info(){
  1515. $bargainNo = isset($this->post['bargainNo'])&& $this->post['bargainNo']!=""?trim($this->post['bargainNo']):"";
  1516. if($bargainNo===""){
  1517. return error_show(1004,"参数bargainNo不能为空");
  1518. }
  1519. $info =Db::name("bargain_order")->where(['bargainNo'=>$bargainNo,"is_del"=>0])->find();
  1520. if($info==false){
  1521. return error_show(1004,"未找到议价数据");
  1522. }
  1523. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$info['bidsNo']],["is_del","=",0]])->find();
  1524. if($bidinfos==false){
  1525. return error_show(1004,"未找到商品数据");
  1526. }
  1527. $consultinfos =Db::name("consult_info")->where([["infoNo","=",$bidinfos['infoNo']],["is_del","=",0]])->find();
  1528. if($consultinfos==false){
  1529. return error_show(1004,"未找到咨询商品数据");
  1530. }
  1531. $info['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1532. $info['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1533. $info['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1534. $info['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1535. $info['good_num'] = isset($consultinfos['num'])?$consultinfos['num']:"";
  1536. $info['before_rate'] =round($info['before_rate']*100,2);
  1537. $info['sale_price'] =round($bidinfos['origin_price'],2);
  1538. $info['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1539. $info['after_rate'] = round($info['after_rate']*100,2);
  1540. $info['exam_info'] = isset($info['exam_info'])&&$info['exam_info']!=""?json_decode($info['exam_info'],true):"";
  1541. if($bidinfos['brand_id']!=0){
  1542. $info['brand_id'] = $bidinfos['brand_id'];
  1543. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1544. $info["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1545. }else{
  1546. $info["brand_name"]="";
  1547. $info["brand_id"]="";
  1548. }
  1549. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1550. $info['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1551. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1552. $info['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1553. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$info["infoNo"]])->find();
  1554. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1555. $lower_rate = isset($catinfo['lower_rate']) ? $catinfo['lower_rate']/100:0;//boss主管利率
  1556. $info['budget'] =$budget;
  1557. $info['rate_status'] =0; //利率状态 0 业务主管利率无法通过 1 财务主管利率无法通过 2 boos利率无法通过 3 完全通过
  1558. if($info['after_rate']>=$catinfo['rate']){
  1559. //业务主管利率
  1560. $info['rate_status'] =1;
  1561. }
  1562. elseif ($info['after_rate']>=$catinfo['money_rate']){
  1563. //财务主管利率
  1564. $info['rate_status'] =2;
  1565. }
  1566. elseif ($info['after_rate']>=$catinfo['lower_rate']){
  1567. //boss利率
  1568. $info['rate_status'] =3;
  1569. }
  1570. $god=[
  1571. "metal_id"=>$bidinfos['metal_id'],
  1572. "weight"=>$bidinfos["good_weight"],
  1573. "demo_fee"=>$bidinfos["demo_fee"],
  1574. "delivery_fee"=>$bidinfos["delivery_fee"],
  1575. "open_fee"=>$bidinfos["open_fee"],
  1576. "packing_fee"=>$bidinfos["pakge_fee"],
  1577. "mark_fee"=>$bidinfos["mark_fee"],
  1578. "nake_fee"=>$bidinfos["nake_fee"],
  1579. "cert_fee"=>$bidinfos["cert_fee"],
  1580. "cost_fee"=>$bidinfos["cost_fee"],
  1581. "num"=>$bidinfoe["num"],
  1582. ];
  1583. $info['gold_price']=0;
  1584. $info['noble_weight']=$bidinfos['good_weight'];
  1585. if($bidinfos['is_gold_price']==1 &&$bidinfos['metal_id']>0){
  1586. $gold = Db::name("gold_price1")->where(["type"=>$bidinfos["metal_id"],"is_del"=>0,"status"=>1])->order("addtime desc")
  1587. ->find();
  1588. $info['gold_price'] =$gold['price'];
  1589. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num'] + $bidinfos['good_weight']* $gold["price"] +$bidinfos['cost_fee']*$bidinfos['good_weight'] + $bidinfos['pakge_fee'] +$bidinfos['mark_fee'] + $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1590. }else{
  1591. if($bidinfos['nake_fee']!=0){
  1592. $lower_price =($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'] + $bidinfos['nake_fee']) / (1 - $lower_rate);
  1593. }else{
  1594. $lower_price = ($bidinfos['demo_fee']/$consultinfos['num']+$bidinfos['delivery_fee']+$bidinfos['open_fee']/$consultinfos['num']+$bidinfos['cost_fee']*$bidinfos['good_weight']+$bidinfos['pakge_fee'] +$bidinfos['mark_fee']+ $bidinfos['cert_fee'])/ (1 - $lower_rate);
  1595. }
  1596. }
  1597. $info['cost_desc'] =$bidinfos['cost_desc'];
  1598. $info['work_day'] =$bidinfos['work_day'];
  1599. $info['delivery_day'] =$bidinfos['delivery_day'];
  1600. $info['expire_day'] =$bidinfos['expire_day'];
  1601. $info['origin_place'] =$bidinfos['origin_place'];
  1602. $info['origin_addr'] ="";
  1603. if($bidinfos['origin_place']!=''){
  1604. $code = explode(",",$bidinfos['origin_place']);
  1605. $temp=[];
  1606. $temp['provice_code']=isset($code[0])?$code[0]:"";
  1607. $temp['city_code']=isset($code[1])?$code[1]:"";
  1608. $temp['area_code']=isset($code[2])?$code[2]:"";
  1609. $addr= GetAddr(json_encode($temp));
  1610. $info['origin_addr'] = $addr;
  1611. }
  1612. $info['supplierNo'] =$bidinfos['supplierNo'];
  1613. $supplier = Db::name("supplier")->where(["code"=>$info['supplierNo']])->find();
  1614. $info['supplier_name'] = isset($supplier['name'])?$supplier['name']:"";
  1615. $info['pay_way'] =$bidinfos['pay_way'];
  1616. $info['tax'] =$bidinfos['tax'];
  1617. $info['send_way'] =$bidinfos['send_way'];
  1618. $info['metal_id'] =$bidinfos['metal_id'];
  1619. $info['is_gold_price'] =$bidinfos['is_gold_price'];
  1620. $info['config'] =$bidinfos['config'];
  1621. $info['other_config'] =$bidinfos['other_config'];
  1622. $info['weight'] =$bidinfos['weight'];
  1623. $info['good_weight'] =$bidinfos['good_weight'];
  1624. $info['is_diff'] =$bidinfos['is_diff'];
  1625. $info['demo_fee'] =$bidinfos['demo_fee'];
  1626. $info['delivery_fee'] =$bidinfos['delivery_fee'];
  1627. $info['open_fee'] =$bidinfos['open_fee'];
  1628. $info['pakge_fee'] =$bidinfos['pakge_fee'];
  1629. $info['nake_fee'] =$bidinfos['nake_fee'];
  1630. $info['mark_fee'] =$bidinfos['mark_fee'];
  1631. $info['cert_fee'] =$bidinfos['cert_fee'];
  1632. $info['cost_fee'] =$bidinfos['cost_fee'];
  1633. $info['total_fee'] =$bidinfos['total_fee'];
  1634. $info['supply_area'] =$bidinfos['supply_area'];
  1635. $info['remark'] =$bidinfos['remark'];
  1636. $info['is_addrs'] =$consultinfos['is_addrs'];
  1637. $info['is_custom'] =$consultinfos['is_custom'];
  1638. $info['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1639. // $info['sale_price'] =round($bidinfos['sale_price'],2);//议价前价格
  1640. $info['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1641. if($info['status']==7){
  1642. $info['lower_price'] =round($lower_price,2);
  1643. }
  1644. //获取议价原因
  1645. if ($info['result_info_id'] != 0) {
  1646. $info['result_info'] = Db::name('result_info')->where(['result_code' => $info['result_info_id'], 'type' => 7, 'status' => 1, 'is_del' => 0])->value('result');
  1647. } else {
  1648. $info['result_info'] = '';
  1649. }
  1650. return app_show(0,"获取成功",$info);
  1651. }
  1652. public function bidlist(){
  1653. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1654. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1655. $where=[['is_del',"=",0]];
  1656. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1657. if ($zxNo !== "") {
  1658. $where[] = ['zxNo','like','%'.$zxNo.'%'];
  1659. }
  1660. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1661. if ($infoNo !== "") {
  1662. $where[] = ['infoNo','like','%'.$infoNo.'%'];
  1663. }
  1664. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1665. if ($bidNo !== "") {
  1666. $where[] = ['bidNo','like','%'.$bidNo.'%'];
  1667. }
  1668. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1669. if ($pgNo !== "") {
  1670. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1671. $where[] = ['infoNo','in',$bidinfo];
  1672. }
  1673. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  1674. if ($bargain_status !== "") {
  1675. $bidinfo = Db::name("consult_info")->where([["bargain_status","=",$bargain_status],["is_del","=",0]])->column("infoNo");
  1676. $where[] = ['infoNo','in',$bidinfo];
  1677. }
  1678. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1679. if ($projectNo !== "") {
  1680. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1681. ("zxNo");
  1682. $where[] = ['zxNo','in',$zxlist];
  1683. }
  1684. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1685. if($is_own==1){
  1686. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1687. if($token==""){
  1688. return error_show(101,'token不能为空');
  1689. }
  1690. $apply_id =GetUserInfo($token);
  1691. if(empty($apply_id)||$apply_id['code']!=0){
  1692. return error_show(1002,"申请人数据不存在");
  1693. }
  1694. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1695. $where[]=['createrid',"=",$rm];
  1696. }
  1697. $count = Db::name('consult_bids')->where($where)->count();
  1698. $total = ceil($count / $size);
  1699. $page = $page >= $total ? $total : $page;
  1700. $list =Db::name('consult_bids')->where($where)->page($page,$size)->select()->toArray();
  1701. $data=[];
  1702. foreach ($list as $value){
  1703. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1704. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1705. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1706. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1707. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1708. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1709. if($value['brand_id']!=0){
  1710. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1711. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1712. }else{
  1713. $value["brand_name"]="";
  1714. $value["brand_id"]="";
  1715. }
  1716. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1717. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1718. $god=[
  1719. "metal_id"=>$value['metal_id'],
  1720. "weight"=>$value["good_weight"],
  1721. "demo_fee"=>$value["demo_fee"],
  1722. "delivery_fee"=>$value["delivery_fee"],
  1723. "open_fee"=>$value["open_fee"],
  1724. "packing_fee"=>$value["pakge_fee"],
  1725. "mark_fee"=>$value["mark_fee"],
  1726. "nake_fee"=>$value["nake_fee"],
  1727. "cert_fee"=>$value["cert_fee"],
  1728. // "cost_fee"=>$value["cost_fee"],
  1729. "cost_fee"=>$value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_cost_fee"]: $value["cost_fee"],
  1730. //暂时注掉,搞不清楚原因@吴广广
  1731. "num"=>$bidinfo["num"],
  1732. ];
  1733. $top_cat = made($value['cat_id']);
  1734. $top_cat_id = isset($top_cat[0]['id'])?$top_cat[0]['id']:0;
  1735. if($value['is_gold_price']==1 && $top_cat_id==6 ){
  1736. $price = GoldPrice($god, $budget/100);
  1737. $value['sale_price'] = round($price,2);
  1738. $value['origin_price'] = $value["sale_cost_fee"]!=$value['origin_cost_fee']? $value["sale_price"]:
  1739. $value["origin_price"];
  1740. }
  1741. $value['cost_fee'] =$value['origin_cost_fee'];
  1742. $value['specinfo'] = json_decode($value['specinfo'],true);
  1743. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1744. $value['bargain_status']=$bidinfo['bargain_status'];
  1745. //reject驳回原因,status==5表示驳回
  1746. $value['reject']=[];
  1747. if ($value['status'] >=5) {
  1748. $value['reject'] = Db::name('bargain_order')
  1749. ->field('id,remark,status')
  1750. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  1751. ->whereIn('status', [3,8,11])->order("id desc")
  1752. ->find();
  1753. }
  1754. //产地
  1755. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1756. if($value['delivery_place']!=""){
  1757. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['delivery_place']);
  1758. }
  1759. $value['delivery_place_cn']=GetAddr(json_encode($place));
  1760. $place = ["provice_code"=>"","city_code"=>"","area_code"=>""];
  1761. if($value['origin_place']!=""){
  1762. list($place['provice_code'],$place['city_code'],$place['area_code'])=explode(",",$value['origin_place']);
  1763. }
  1764. $value['origin_addr']=GetAddr(json_encode($place));
  1765. // if($value['origin_place']!=''){
  1766. // $code = explode(",",$value['origin_place']);
  1767. // $temp=[];
  1768. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  1769. // $temp['city_code']=isset($code[1])?$code[1]:"";
  1770. // $temp['area_code']=isset($code[2])?$code[2]:"";
  1771. // $addr= GetAddr(json_encode($temp));
  1772. // $value['origin_addr'] = $addr;
  1773. // }
  1774. $data[] = $value;
  1775. }
  1776. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  1777. }
  1778. public function feedlist(){
  1779. $where=[['is_del',"=",0]];
  1780. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1781. if ($zxNo !== "") {
  1782. $where[] = ['zxNo','=',$zxNo];
  1783. }
  1784. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1785. if ($infoNo !== "") {
  1786. $where[] = ['infoNo','=',$infoNo];
  1787. }
  1788. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  1789. if ($bidNo !== "") {
  1790. $where[] = ['bidNo','=',$bidNo];
  1791. }
  1792. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1793. if ($projectNo !== "") {
  1794. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1795. ("zxNo");
  1796. $where[] = ['zxNo','in',$zxlist];
  1797. }
  1798. $token = isset($this->post['token'])&& $this->post['token']!='' ? trim($this->post['token']):"";
  1799. if($token==''){
  1800. return error_show(102,"参数token不能为空");
  1801. }
  1802. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  1803. if($is_own==1){
  1804. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  1805. if($token==""){
  1806. return error_show(101,'token不能为空');
  1807. }
  1808. $apply_id =GetUserInfo($token);
  1809. if(empty($apply_id)||$apply_id['code']!=0){
  1810. return error_show(1002,"申请人数据不存在");
  1811. }
  1812. $rm= isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  1813. $where[]=['createrid',"=",$rm];
  1814. }
  1815. $list =Db::name('consult_bids')->where($where)->select();
  1816. $data=[];
  1817. foreach ($list as $value){
  1818. $catinfo = Db::name("cat")->where(["id"=>$value['cat_id']])->find();
  1819. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  1820. $unit =Db::name("unit")->where(["id"=>$value['unit_id']])->find();
  1821. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1822. $supplier = Db::name("supplier")->where(["code"=>$value['supplierNo']])->find();
  1823. $value['supplierName'] = isset($supplier['name'])?$supplier['name']:"";
  1824. if($value['brand_id']!=0){
  1825. $brand=Db::name("brand")->where(["id"=>$value['brand_id']])->find();
  1826. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1827. }else{
  1828. $value["brand_name"]="";
  1829. $value["brand_id"]="";
  1830. }
  1831. $bidinfo = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1832. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1833. $god=[
  1834. "metal_id"=>$value['metal_id'],
  1835. "weight"=>$value["good_weight"],
  1836. "demo_fee"=>$value["demo_fee"],
  1837. "delivery_fee"=>$value["delivery_fee"],
  1838. "open_fee"=>$value["open_fee"],
  1839. "packing_fee"=>$value["pakge_fee"],
  1840. "mark_fee"=>$value["mark_fee"],
  1841. "nake_fee"=>$value["nake_fee"],
  1842. "cert_fee"=>$value["cert_fee"],
  1843. "cost_fee"=>$value["cost_fee"],
  1844. "num"=>$bidinfo["num"],
  1845. ];
  1846. if ($value['is_gold_price'] == 1 ) {
  1847. $gold = Db::name("gold_price1")->where(["type"=>$value['metal_id'],"is_del"=>0,"status"=>1])->order("addtime desc")
  1848. ->find();
  1849. //$total_fee(成本合计初始价格) =打样费/购买数量 + 开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价0+运费;
  1850. //$saleprice(最终售价) = (开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100);
  1851. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num'] +$value["good_weight"] *$gold["price"] +
  1852. $value["cost_fee"] * $value["good_weight"] + $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) / (1 - $budget);
  1853. // //销售工艺费=((开模费/购买数量 + 商品重量* 最新金价 + 工艺费* 商品重量+包装费+加标费+证书费+产品裸价)/(1-成本售价/100)-(打样费/购买数量 + 开模费/购买数量 +包装费+加标费+证书费+产品裸价0+运费) )/商品重量-最新金价
  1854. // $sale_cost_fee = (($open_fee / $zxinfo['num'] + $weight * $gold["price"] + $cost_fee * $weight + $pakge_fee + $mark_fee + $cert_fee + $nake_fee) / (1 - $budget) - ($demo_fee / $zxinfo['num'] + $open_fee / $zxinfo['num'] + $pakge_fee + $mark_fee + $cert_fee + $nake_fee + $delivery_fee)) / $weight - $gold["price"];
  1855. }else{
  1856. if($value["nake_fee"]){
  1857. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"])/ (1 - $budget);
  1858. }else{
  1859. $saleprice = ($value['demo_fee']/$bidinfo['num']+$value['delivery_fee']+$value["open_fee"]/$bidinfo['num']+$value["cost_fee"] * $value["good_weight"]+ $value["pakge_fee"]+ $value["mark_fee"] +$value["cert_fee"] +$value["nake_fee"]) /
  1860. (1 - $budget);
  1861. }
  1862. }
  1863. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  1864. $value['specinfo'] = json_decode($value['specinfo'],true);
  1865. $value['bargain_status']=$bidinfo['bargain_status'];
  1866. $data[]=$value;
  1867. }
  1868. return app_show(0,"获取成功",$data);
  1869. }
  1870. public function bragain_list(){
  1871. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1872. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1873. $where=[['bo.is_del',"=",0]];
  1874. $bidsNo = isset($this->post['bidsNo'])&&$this->post['bidsNo']!=""?trim($this->post['bidsNo']):"";
  1875. if($bidsNo!=""){
  1876. $where[]=["bo.bidsNo","like","%$bidsNo%"];
  1877. }
  1878. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1879. if ($zxNo !== "") {
  1880. $where[] = ['bo.zxNo','like',"%$zxNo%"];
  1881. }
  1882. $bargainNo = isset($this->post['bargainNo']) && $this->post['bargainNo'] !== "" ? trim($this->post['bargainNo']) : "";
  1883. if ($bargainNo !== "") {
  1884. $where[] = ['bo.bargainNo','like',"%$bargainNo%"];
  1885. }
  1886. $status = isset($this->post['status']) && $this->post['status'] !== "" ? intval($this->post['status']) : "";
  1887. if ($status!== "") {
  1888. $where[] = ['bo.status','=',$status];
  1889. }
  1890. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  1891. if ($infoNo !== "") {
  1892. $where[] = ['bo.infoNo','like',"%$infoNo%"];
  1893. }
  1894. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  1895. if ($projectNo !== "") {
  1896. $zxlist = Db::name("consult_order")->where(["projectNo"=>$projectNo,"is_del"=>0,"is_project"=>1])->column
  1897. ("zxNo");
  1898. $where[] = ['bo.zxNo','in',$zxlist];
  1899. }
  1900. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  1901. if ($pgNo !== "") {
  1902. $bidinfo = Db::name("consult_info")->where([["pgNo","=",$pgNo],["is_del","=",0]])->column("infoNo");
  1903. $where[] = ['bo.infoNo','in',$bidinfo];
  1904. }
  1905. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start'] : "";
  1906. $end= isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] : "";
  1907. if($start!=""){
  1908. $where[]=["bo.addtime",">=",date("Y-m-d H:i:s",strtotime($start))];
  1909. }
  1910. if($end!=""){
  1911. $where[]=["bo.addtime","<=",date("Y-m-d H:i:s",strtotime($end))];
  1912. }
  1913. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  1914. if ($company_name !== "") $where[] = ["bo.createrid", 'in', get_company_item_user_by_name($company_name)];
  1915. $role=$this->checkRole();
  1916. if(!empty($role['write'])){
  1917. $where[]=["bo.createrid","in",$role['write']];
  1918. }
  1919. $count=Db::name("bargain_order")->alias('bo')->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")->where($where)->count();
  1920. $total = ceil($count / $size);
  1921. $page = $page >= $total ? $total : $page;
  1922. $list = Db::name('bargain_order')
  1923. ->alias('bo')
  1924. ->field('bo.*,u.itemid')
  1925. ->leftJoin("depart_user u", "u.uid=bo.createrid AND u.is_del=0")
  1926. ->where($where)
  1927. ->page($page, $size)
  1928. ->order('bo.addtime', 'desc')
  1929. ->cursor();
  1930. $data=[];
  1931. foreach ($list as $value){
  1932. $bidinfos = Db::name("consult_bids")->where([["bidNo","=",$value['bidsNo']],["is_del","=",0]])->find();
  1933. $value['spuCode'] = isset($bidinfos['spuCode'])?$bidinfos['spuCode']:"";
  1934. $value['good_name'] = isset($bidinfos['good_name'])?$bidinfos['good_name']:"";
  1935. $value['good_img'] = isset($bidinfos['good_img'])?$bidinfos['good_img']:"";
  1936. $value['brand_id'] = isset($bidinfos['brand_id'])?$bidinfos['brand_id']:"";
  1937. if($bidinfos['brand_id']!=0){
  1938. $value['brand_id'] = $bidinfos['brand_id'];
  1939. $brand=Db::name("brand")->where(["id"=>$bidinfos['brand_id']])->find();
  1940. $value["brand_name"]=isset($brand['brand_name'])?$brand['brand_name']:"";
  1941. }else{
  1942. $value["brand_name"]="";
  1943. $value["brand_id"]="";
  1944. }
  1945. $catinfo = Db::name("cat")->where(["id"=>$bidinfos['cat_id']])->find();
  1946. $value['can']= isset($bidinfos['cat_id']) && $bidinfos['cat_id'] !=0 ? made($bidinfos['cat_id']):[];
  1947. $unit =Db::name("unit")->where(["id"=>$bidinfos['unit_id']])->find();
  1948. $value['unit'] = isset($unit['unit'])?$unit['unit']:'';
  1949. $bidinfoe = Db::name("consult_info")->where(["infoNo"=>$value["infoNo"]])->find();
  1950. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate']:0;
  1951. $value['budget'] =$budget;
  1952. $god=[
  1953. "metal_id"=>$bidinfos['metal_id'],
  1954. "weight"=>$bidinfos["good_weight"],
  1955. "demo_fee"=>$bidinfos["demo_fee"],
  1956. "delivery_fee"=>$bidinfos["delivery_fee"],
  1957. "open_fee"=>$bidinfos["open_fee"],
  1958. "packing_fee"=>$bidinfos["pakge_fee"],
  1959. "mark_fee"=>$bidinfos["mark_fee"],
  1960. "nake_fee"=>$bidinfos["nake_fee"],
  1961. "cert_fee"=>$bidinfos["cert_fee"],
  1962. "cost_fee"=>$bidinfos["cost_fee"],
  1963. "num"=>$bidinfoe["num"],
  1964. ];
  1965. // if($bidinfos['is_gold_price']==1){
  1966. // $price = GoldPrice($god, $budget/100);
  1967. // }else{
  1968. // $price = GoodPrice($god, $budget/100);
  1969. // }
  1970. $value['metal_name']=isset($bidinfos['metal_id'])&& $bidinfos['metal_id']!=0?$this->noble[$bidinfos['metal_id']]:"";
  1971. $value['sale_price'] =round($bidinfos['origin_price'],2);
  1972. $value['cost_before_price'] =round($bidinfos['origin_cost_fee'],2);
  1973. $value['specinfo'] = isset($bidinfos['specinfo'])&&$bidinfos['specinfo']!=""?json_decode($bidinfos['specinfo'],true):[];
  1974. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  1975. $data[]=$value;
  1976. }
  1977. return app_show(0,"获取成功",["list"=>$data,"count"=>$count]);
  1978. }
  1979. public function crontablist(){
  1980. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) :"1";
  1981. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) :"10";
  1982. $where=[['a.is_del',"=",0],['b.is_del',"=",0]];
  1983. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  1984. if ($zxNo !== "") {
  1985. $where[] = ['a.zxNo','=',$zxNo];
  1986. }
  1987. $salesman = isset($this->post['salesman']) && $this->post['salesman'] !== "" ? trim($this->post['salesman']) : "";
  1988. if ($salesman !== "") {
  1989. //$where["salesman"] =Db::Raw("like '%$salesman%'");
  1990. $where[]= ["b.salesman",'like',"%$salesman%"];
  1991. }
  1992. $cpName = isset($this->post['cpName']) && $this->post['cpName'] !== "" ? trim($this->post['cpName']) : "";
  1993. if ($cpName !== "") {
  1994. //$where["cpName"]= Db::Raw("like '%$cpName%'");
  1995. $where[]= ["a.good_Name",'like',"%$cpName%"];
  1996. }
  1997. $khNo = isset($this->post['khNo']) && $this->post['khNo'] !== "" ? trim($this->post['khNo']) : "";
  1998. if ($khNo !== "") {
  1999. // $where['khNo'] = $khNo;
  2000. $where[]= ["b.khNo",'like',"%$khNo%"];
  2001. }
  2002. $start= isset($this->post['start']) && $this->post['start'] !== "" ? $this->post['start']:"";
  2003. if ($start !="") {
  2004. //$where = ["zxtime"=>Db::raw(">= '{$start}'")];
  2005. $where[]= ["a.addtime",'>=',$start];
  2006. }
  2007. $end = isset($this->post['end']) && $this->post['end'] !== "" ? $this->post['end'] :"";
  2008. if($end !=""){
  2009. $where[]= ["a.addtime",'<=',$end];
  2010. }
  2011. $status = isset($this->post['status']) && $this->post['status'] !== "" ? trim($this->post['status']) : "";
  2012. if ($status !== "") {
  2013. $where[]= ["a.status",'=',$status];
  2014. }
  2015. // $role=$this->checkRole();
  2016. // if(!empty($role['platform']) ){
  2017. // $where[]=["b.platform_code","in",$role['platform']];
  2018. // }
  2019. $count = Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)
  2020. ->count();
  2021. $total = ceil($count / $size);
  2022. $page = $page >= $total ? $total : $page;
  2023. $list =Db::name('consult_info')->alias("a")->leftJoin("consult_order b","a.zxNo=b.zxNo")->where($where)->page($page,$size)
  2024. ->field("a.*,b.createrid,b.creater,b.is_project,b.projectNo,b.khNo,b.endtime,b.platform_code,b.saleid,b.salesman,b.depart")->select();
  2025. $data=[];
  2026. foreach ($list as $value){
  2027. $value['can']= isset($value['cat_id']) && $value['cat_id'] !=0 ? made($value['cat_id']):[];
  2028. $brand = Db::name("brand")->where(['id'=>$value['brand_id']])->find();
  2029. $value['brand_name']= isset($brand['brand_name']) && $brand['brand_name']!='' ? $brand['brand_name']:"";
  2030. $value['khname']="";
  2031. $value['specinfo']=isset($value['specinfo'])&&$value['specinfo']!=""? json_decode($value['specinfo'],
  2032. true):[];
  2033. if($value['khNo']!==""){
  2034. $kh=Db::name("customer_info")->where(['companyNo'=>$value['khNo']])->find();
  2035. $value['khname']= isset($kh['companyName'])?$kh['companyName']:"";
  2036. }
  2037. $consult =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"createrid"=>$this->uid,"is_del"=>0])
  2038. ->find();
  2039. $consults =Db::name("consult_bids")->where(["infoNo"=>$value['infoNo'],"is_del"=>0])->find();
  2040. $value['is_feed'] =$consult==false?0:1;
  2041. $value['is_all_feed'] =$consults==false?0:1;
  2042. $value['metal_name']=isset($value['metal_id'])&& $value['metal_id']!=0?$this->noble[$value['metal_id']]:"";
  2043. $data[]=$value;
  2044. }
  2045. return app_show(0,"获取成功",['count'=>$count,'list'=>$data]);
  2046. }
  2047. //复制上面的bidlist方法,只更改排序方式
  2048. public function bidlistCopy()
  2049. {
  2050. $page = isset($this->post['page']) && $this->post['page'] !== "" ? intval($this->post['page']) : "1";
  2051. $size = isset($this->post['size']) && $this->post['size'] !== "" ? intval($this->post['size']) : "10";
  2052. $where = [['cb.is_del', "=", 0]];
  2053. $zxNo = isset($this->post['zxNo']) && $this->post['zxNo'] !== "" ? trim($this->post['zxNo']) : "";
  2054. if ($zxNo !== "") {
  2055. $where[] = ['cb.zxNo', 'like', '%' . $zxNo . '%'];
  2056. }
  2057. $infoNo = isset($this->post['infoNo']) && $this->post['infoNo'] !== "" ? trim($this->post['infoNo']) : "";
  2058. if ($infoNo !== "") {
  2059. $where[] = ['cb.infoNo', 'like', '%' . $infoNo . '%'];
  2060. }
  2061. $bidNo = isset($this->post['bidNo']) && $this->post['bidNo'] !== "" ? trim($this->post['bidNo']) : "";
  2062. if ($bidNo !== "") {
  2063. $where[] = ['cb.bidNo', 'like', '%' . $bidNo . '%'];
  2064. }
  2065. $pgNo = isset($this->post['pgNo']) && $this->post['pgNo'] !== "" ? trim($this->post['pgNo']) : "";
  2066. if ($pgNo !== "") {
  2067. $bidinfo = Db::name("consult_info")->where([["pgNo", "=", $pgNo], ["is_del", "=", 0]])->column("infoNo");
  2068. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2069. }
  2070. $bargain_status = isset($this->post['bargain_status']) && $this->post['bargain_status'] !== "" ? intval($this->post['bargain_status']) : "";
  2071. if ($bargain_status !== "") {
  2072. $bidinfo = Db::name("consult_info")->where([["bargain_status", "=", $bargain_status], ["is_del", "=", 0]])->column("infoNo");
  2073. $where[] = ['cb.infoNo', 'in', $bidinfo];
  2074. }
  2075. $projectNo = isset($this->post['projectNo']) && $this->post['projectNo'] !== "" ? trim($this->post['projectNo']) : "";
  2076. if ($projectNo !== "") {
  2077. $zxlist = Db::name("consult_order")->where(["projectNo" => $projectNo, "is_del" => 0, "is_project" => 1])->column
  2078. ("zxNo");
  2079. $where[] = ['cb.zxNo', 'in', $zxlist];
  2080. }
  2081. $is_own = isset($this->post['is_own']) ? intval($this->post['is_own']) : "0";
  2082. if ($is_own == 1) {
  2083. $token = isset($this->post['token']) ? trim($this->post['token']) : "";
  2084. if ($token == "") {
  2085. return error_show(101, 'token不能为空');
  2086. }
  2087. $apply_id = GetUserInfo($token);
  2088. if (empty($apply_id) || $apply_id['code'] != 0) {
  2089. return error_show(1002, "申请人数据不存在");
  2090. }
  2091. $rm = isset($apply_id["data"]['id']) ? $apply_id["data"]['id'] : "";
  2092. $where[] = ['cb.createrid', "=", $rm];
  2093. }
  2094. $company_name = isset($this->post['company_name']) && $this->post['company_name'] !== "" ? trim($this->post['company_name']) : "";
  2095. if ($company_name !== "") $where[] = ["cb.createrid", 'in', get_company_item_user_by_name($company_name)];
  2096. $count = Db::name('consult_bids')->alias('cb')->where($where)->count();
  2097. $total = ceil($count / $size);
  2098. $page = $page >= $total ? $total : $page;
  2099. $list = Db::name('consult_bids')
  2100. ->alias('cb')
  2101. ->field('cb.*,u.itemid')
  2102. ->leftJoin("depart_user u", "u.uid=cb.createrid AND u.is_del=0")
  2103. ->where($where)
  2104. ->page($page, $size)
  2105. ->order('cb.addtime', 'desc')
  2106. ->cursor();
  2107. $data = [];
  2108. foreach ($list as $value) {
  2109. $catinfo = Db::name("cat")->where(["id" => $value['cat_id']])->find();
  2110. $value['can'] = isset($value['cat_id']) && $value['cat_id'] != 0 ? made($value['cat_id']) : [];
  2111. $unit = Db::name("unit")->where(["id" => $value['unit_id']])->find();
  2112. $value['unit'] = isset($unit['unit']) ? $unit['unit'] : '';
  2113. $supplier = Db::name("supplier")->where(["code" => $value['supplierNo']])->find();
  2114. $value['supplierName'] = isset($supplier['name']) ? $supplier['name'] : "";
  2115. if ($value['brand_id'] != 0) {
  2116. $brand = Db::name("brand")->where(["id" => $value['brand_id']])->find();
  2117. $value["brand_name"] = isset($brand['brand_name']) ? $brand['brand_name'] : "";
  2118. } else {
  2119. $value["brand_name"] = "";
  2120. $value["brand_id"] = "";
  2121. }
  2122. $bidinfo = Db::name("consult_info")->where(["infoNo" => $value["infoNo"]])->find();
  2123. $budget = isset($catinfo['order_rate']) ? $catinfo['order_rate'] : 0;
  2124. $god = [
  2125. "metal_id" => $value['metal_id'],
  2126. "weight" => $value["good_weight"],
  2127. "demo_fee" => $value["demo_fee"],
  2128. "delivery_fee" => $value["delivery_fee"],
  2129. "open_fee" => $value["open_fee"],
  2130. "packing_fee" => $value["pakge_fee"],
  2131. "mark_fee" => $value["mark_fee"],
  2132. "nake_fee" => $value["nake_fee"],
  2133. "cert_fee" => $value["cert_fee"],
  2134. "cost_fee" => $value["sale_cost_fee"]!=$value["origin_cost_fee"] ? $value["sale_cost_fee"] : $value["cost_fee"],
  2135. "num" => $bidinfo["num"],
  2136. ];
  2137. if ($value['is_gold_price'] == 1) {
  2138. $price = GoldPrice($god, $budget / 100);
  2139. $value['sale_price'] = round($price, 2);
  2140. }
  2141. $value['cost_fee'] = $value['origin_cost_fee'];
  2142. $value['specinfo'] = json_decode($value['specinfo'], true);
  2143. $value['metal_name'] = isset($value['metal_id']) && $value['metal_id'] != 0 ? $this->noble[$value['metal_id']] : "";
  2144. $value['bargain_status'] = $bidinfo['bargain_status'];
  2145. //reject驳回原因,status==5表示驳回
  2146. $value['reject'] = [];
  2147. if ($value['status'] >= 5) {
  2148. $value['reject'] = Db::name('bargain_order')
  2149. ->field('id,remark,status')
  2150. ->where(['infoNo' => $infoNo, 'bidsNo' => $value['bidNo']])
  2151. ->whereIn('status', [3, 8, 11])->order("id desc")
  2152. ->find();
  2153. }
  2154. //产地
  2155. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2156. if ($value['delivery_place'] != "") {
  2157. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['delivery_place']);
  2158. }
  2159. $value['delivery_place_cn'] = GetAddr(json_encode($place));
  2160. $place = ["provice_code" => "", "city_code" => "", "area_code" => ""];
  2161. if ($value['origin_place'] != "") {
  2162. list($place['provice_code'], $place['city_code'], $place['area_code']) = explode(",", $value['origin_place']);
  2163. }
  2164. $value['origin_addr'] = GetAddr(json_encode($place));
  2165. // if($value['origin_place']!=''){
  2166. // $code = explode(",",$value['origin_place']);
  2167. // $temp=[];
  2168. // $temp['provice_code']=isset($code[0])?$code[0]:"";
  2169. // $temp['city_code']=isset($code[1])?$code[1]:"";
  2170. // $temp['area_code']=isset($code[2])?$code[2]:"";
  2171. // $addr= GetAddr(json_encode($temp));
  2172. // $value['origin_addr'] = $addr;
  2173. // }
  2174. $value['company_name'] = implode('/', array_column(GetPart($value['itemid']), 'name'));
  2175. $data[] = $value;
  2176. }
  2177. return app_show(0, "获取成功", ['count' => $count, 'list' => $data]);
  2178. }
  2179. }